Pylint: Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object.

Created on 29 Mar 2018  路  28Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. Install Visual Studio Code
  2. Install python support and install pylint
  3. Setup basic flask app
  4. Create Blueprint and import db from main __init__.py

Current behavior

severity: 'Error'
message: 'E1101:Instance of 'SQLAlchemy' has no 'Column' member'
at: '14,10'
source: 'pylint'
code: 'E1101'

Expected behavior

No errors (since code / application works as expected)

pylint --version output

No config file found, using default configuration
pylint 1.8.3,
astroid 1.6.2
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]

For more details check following thread:
https://github.com/Microsoft/vscode-python/issues/292

astroid brain bug wont fix

Most helpful comment

I find an elegant solution here: https://stackoverflow.com/questions/28193025/pylint-cant-find-sqlalchemy-query-member

Solution

pip install pylint-flask

Load the installed plugin.

For example, if you use VS code, please edit setting.json file as follows:

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]

All 28 comments

Thanks, I think we don't understand any of Sqlalchemy's library. This might require some updates in astroid's brain tips to support sqlalchemy by providing hints on how the library looks.

I added a solution at Microsoft/vscode-python#292

Let me know if that helped !!!

@anselal changing linter seems to be workaround but not a solution

I guess you are right @ibakirov

Bump.

Same problem.Python 3.6.4 VSCode 1.26.1, pylint 2.1.1, astroid 2.0.4. 160 errors all of the form E1101:Instance of 'SQLAlchemy' has no 'foo' member'. For every type defined in SQLAlchemy model (flask_sqlalchemy http://flask-sqlalchemy.pocoo.org/2.3/):

BigInteger, Boolean, Column, Integer, Unicode, etc.

Current solution for me is to disable pylint and use flake8.

@changeling yes, I'm still using @anselal's workaround

For folks commenting here about switching to flake8, there are multiple solutions to this problem without waiting for a solution from pylint itself:

  • run it with --generated-members=Column
  • or maybe --ignored-classes=SQLAlchemy
  • or disable no-member locally where the error is emitted
  • or even disable it globally

Coming here and commenting that switching to flake8 is a solution to your problem means that you were never interested in the first place to fix it using what pylint offers you already.

And as I mentioned earlier, we don't support sqlalchemy out of the box. Understanding Python code is hard, understanding it when it uses metaclasses and/or other dynamic features is next to impossible, which exactly what is happening with sqlalchemy and flask_sqlalchemy.

How does flake8 deal with it ?

It doesn't. flake8 does not have the same set of checks that pylint has, including this one. no-member is also known for having false positives due to problems I mentioned earlier, but there are solutions to make it "smarter".

I find an elegant solution here: https://stackoverflow.com/questions/28193025/pylint-cant-find-sqlalchemy-query-member

Solution

pip install pylint-flask

Load the installed plugin.

For example, if you use VS code, please edit setting.json file as follows:

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]

After installing the pylint-flask, I stop getting errors at all.

I find an elegant solution here: https://stackoverflow.com/questions/28193025/pylint-cant-find-sqlalchemy-query-member

Solution

pip install pylint-flask

Load the installed plugin.

For example, if you use VS code, please edit setting.json file as follows:

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]

Thank you, it's work for me.

@YoungWilliamZ Is there a solution for newest flask? pylint-flask supports only flask.ext imports, and I don't have those

@Turbid
Same for me, loading the plugin does clear all the errors in the vscode.

However, it also stops detecting other errors. For example:
it stops showing error for db.Column(...)

but it also does not show error for db.Columnasdasda() as well.(I just append random string at the end...)

Is there still no official solution to this issue? I don't want to have to use @YoungWilliamZ solution.

@elamje This is as official as it gets: https://github.com/PyCQA/pylint/issues/1973#issuecomment-418980111

@elamje : I wrote a small pylint plugin to fix these issues : pylint-flask-sqlalchemy if you want to try it.

I find an elegant solution here: https://stackoverflow.com/questions/28193025/pylint-cant-find-sqlalchemy-query-member

Solution

pip install pylint-flask

Load the installed plugin.
For example, if you use VS code, please edit setting.json file as follows:

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]

Thank you, it's work for me. I was having a nightmare debugging the problem...Cheers !!!

Unfortunately, when I installed pylint-flask and added the entry in setting.json, I still got the no member message, along with a whole bunch of others...

+1 on @dxkaufman
EDIT Tried with @rboyer-anybox and it works for me

Use pylint plugin pylint-flask-sqlalchemy

pip install pylint_flask_sqlalchemy

And in your settings.json of VisualCode

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]

"pylint_flask_sqlalcheny" or "pylint_flask_sqlalchemy"?

"pylint_flask_sqlalcheny" or "pylint_flask_sqlalchemy"?

pylint_flask_sqlalchemy, little typo :-)

@herrboyer can't figure out how to contribute on the anycloud site, and this seems like the place people are chatting about your plugin. Is there anyway to have your pylint plugin recognize sqlalchemy's relationship declaration?

ie:

class User:
    name = db.Column(db.String)
    best_friend = db.relationship(User)

    def best_friends_name(self):
        return self.best_friend.name

Code like that is showing errors for pylint: [no-member] Instance of 'relationship' has no 'name' member [E1101]

Hi @btoconnor sorry for the delay... I made a mirror of the repo on github https://github.com/anybox/pylint_flask_sqlalchemy feel free to raise an issue here (btw I was not able to reproduce your problem, I even updated the test data to include a db.relationship)

@YoungWilliamZ
thanks that worked for me as well.

For folks commenting here about switching to flake8, there are multiple solutions to this problem without waiting for a solution from pylint itself:

  • run it with --generated-members=Column
  • or maybe --ignored-classes=SQLAlchemy
  • or disable no-member locally where the error is emitted
  • or even disable it globally

Coming here and commenting that switching to flake8 is a solution to your problem means that you were never interested in the first place to fix it using what pylint offers you already.

And as I mentioned earlier, we don't support sqlalchemy out of the box. Understanding Python code is hard, understanding it when it uses metaclasses and/or other dynamic features is next to impossible, which exactly what is happening with sqlalchemy and flask_sqlalchemy.

Where do i run it?

For folks commenting here about switching to flake8, there are multiple solutions to this problem without waiting for a solution from pylint itself:

  • run it with --generated-members=Column
  • or maybe --ignored-classes=SQLAlchemy
  • or disable no-member locally where the error is emitted
  • or even disable it globally

Coming here and commenting that switching to flake8 is a solution to your problem means that you were never interested in the first place to fix it using what pylint offers you already.
And as I mentioned earlier, we don't support sqlalchemy out of the box. Understanding Python code is hard, understanding it when it uses metaclasses and/or other dynamic features is next to impossible, which exactly what is happening with sqlalchemy and flask_sqlalchemy.

Where do i run it?

My bad already find.
On pylint args in json settings.
Thanks that works for me.

Was this page helpful?
0 / 5 - 0 ratings