anybox / pylint_flask_sqlalchemy

pylint_flask_sqlalchemy is a Pylint plugin to improve static code analysis of Flask-SQLAlchemy based projects.
MIT License
8 stars 5 forks source link

Instance of relationship has no member #1

Closed btoconnor closed 2 years ago

btoconnor commented 4 years ago

As mentioned here, I was seeing the issue. I created a repository illustrating the issue here: https://github.com/btoconnor/pylint-flask-sqlalchemy-bug-demo1

Instructions in the README. Note - the flask app might not work (I didn't run it, the point was to get pylint working), but running pylint shows the issue I'm seeing in my project.

herrboyer commented 4 years ago

Thank you for the detailed report, I was able to reproduce the issue. This might be tricky to solve, I'll keep you posted.

torotil commented 3 years ago

I have a similar issue with a relationship using lazy=dynamic:

class List(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    subscriptions = db.relationship("Subscription", lazy="dynamic")

    def lint_error(self):
        return self.subscriptions.filter(self.id < 0)

class Subscription(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    list_id = db.Column(db.ForeignKey(List.id, ondelete="CASCADE"), nullable=False)

This gives a linting error:

E1101: Instance of 'relationship' has no 'filter' member (no-member)

So relationships can resolve to queries as well as model classes. Still more complexity comes with the custom collection access.