Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive unsubscriptable-object #9549

Open
DarthLegiON opened this issue Apr 13, 2024 · 6 comments
Open

False positive unsubscriptable-object #9549

DarthLegiON opened this issue Apr 13, 2024 · 6 comments
Labels
Lib specific 💅 This affect the code from a particular library Waiting on author Indicate that maintainers are waiting for a message of the author

Comments

@DarthLegiON
Copy link

DarthLegiON commented Apr 13, 2024

Bug description

Hi! I have weird behavior in my code.

Here is a code example:

from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql.sqltypes import String, Integer


class RoleReaction(Base):
    __tablename__ = 'user_roles_reactions'

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    role_name: Mapped[str] = mapped_column(String)
    reaction_name: Mapped[str] = mapped_column(String)
    group_id: Mapped[int] = mapped_column(ForeignKey('user_roles_groups.id'))
    group: Mapped[RoleGroup] = relationship(RoleGroup)

It causes several unsubscriptable-object errors in pylint (look into the output section).

But when I remove the last line (group definition), all of them disappear. When I move it upper, they don't. There is only one file in the whole project that causes such problem.

Configuration

[MASTER]
disable=
    C0114, # missing-module-docstring
    C0115, # missing-class-docstring
    C0116, # missing-function-docstring
    R0903, # too-few-public-methods
    R0801, # similar lines

extension-pkg-allow-list=
    dependency_injector,
    discord

max-line-length=120

Command used

PYTHONPATH=./src pylint --recursive=y --rcfile=.pylintrc ./src/roles_reactions/db.py

Pylint output

************* Module src.roles_reactions.db
src/roles_reactions/db.py:19:8: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/roles_reactions/db.py:20:11: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/roles_reactions/db.py:21:15: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/roles_reactions/db.py:22:19: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/roles_reactions/db.py:23:14: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 9.58/10, -9.58)

Expected behavior

No errors, 10/10

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.10.5 (main, Aug  2 2022, 10:31:34) [GCC 10.2.1 20210110]

OS / Environment

Linux, docker

Additional dependencies

No response

@DarthLegiON DarthLegiON added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 13, 2024
@DanielNoord
Copy link
Collaborator

Hi, without the relevant import statements we won't be able to diagnose the issue. Please make sure to include all relevant code and dependencies :)

@DanielNoord DanielNoord added Waiting on author Indicate that maintainers are waiting for a message of the author and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 19, 2024
@jenstroeger
Copy link

jenstroeger commented Apr 23, 2024

@DarthLegiON thank you for the report, I’ve seen similar problems in my own project. Unfortunately, we didn’t investigate more but in our case deleting the virtual env and rebuilding it worked. Not a fix, I know, but it may unblock you?

@DanielNoord the code shown above is a SQLAlchemy v2 declarative table mapping (docs).

@behnazh-w
Copy link

behnazh-w commented Apr 23, 2024

We have faced a similar problem too.

@jenstroeger deleting the virtual env and rebuilding it doesn't fix our issue. We call pylint using a pre-commit hook. So, I ran pre-commit clean to clean up its cach, but still I face the same issue.

This is the error we get:

src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:36:8: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:39:16: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:42:17: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:45:13: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)

You can find the code here: https://github.com/oracle/macaron/blob/f9be5387ae5ed4e04ceabb9b86579929d2ddcb8f/src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py#L36-L45

@Pierre-Sassoulas Pierre-Sassoulas added the Lib specific 💅 This affect the code from a particular library label Apr 23, 2024
@Pierre-Sassoulas
Copy link
Member

Could you provide the output of pylint --version @behnazh-w, please ? @DarthLegiON I upgraded your example but we still miss the content of Base and RoleGroup, would you mind providing us the detail or create a minimal reproducer, please ?

@behnazh-w
Copy link

behnazh-w commented Apr 23, 2024

Could you provide the output of pylint --version @behnazh-w, please ?

pylint 3.1.0
astroid 3.1.0
Python 3.11.3 (main, Apr  4 2023, 22:36:41) [GCC 11.3.0]

sqlalchemy version:
"SQLAlchemy >=2.0.0,<3.0.0", so 2.0.29 atm.

@jenstroeger
Copy link

I upgraded your example but we still miss the content of Base and RoleGroup, would you mind providing us the detail or create a minimal reproducer, please ?

Base is probably defined as described here and RoleGroup seems to be another table mapping just like the RoleReaction in the example. (It may even be enough to declare an __abstract__ table mapping, for the sake of a reproducible example?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lib specific 💅 This affect the code from a particular library Waiting on author Indicate that maintainers are waiting for a message of the author
Projects
None yet
Development

No branches or pull requests

5 participants