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

Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object. #1973

Closed
r4jk3 opened this issue Mar 29, 2018 · 28 comments
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Won't fix/not planned

Comments

@r4jk3
Copy link

r4jk3 commented Mar 29, 2018

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:
microsoft/vscode-python#292

@PCManticore
Copy link
Contributor

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.

@PCManticore PCManticore added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Bug 🪲 labels Mar 30, 2018
@anselal
Copy link

anselal commented May 8, 2018

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

Let me know if that helped !!!

@ibakirov
Copy link

ibakirov commented Jun 7, 2018

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

@anselal
Copy link

anselal commented Jun 8, 2018

I guess you are right @ibakirov

@changeling
Copy link

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.

@ibakirov
Copy link

ibakirov commented Sep 5, 2018

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

@PCManticore
Copy link
Contributor

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.

@anselal
Copy link

anselal commented Sep 6, 2018

How does flake8 deal with it ?

@vorbit
Copy link

vorbit commented Sep 6, 2018

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".

@YoungWilliamZ
Copy link

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"]

@Turbid
Copy link

Turbid commented Dec 21, 2018

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

@miltonfajardo
Copy link

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.

@krzyk
Copy link

krzyk commented Feb 21, 2019

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

@XiminLin
Copy link

@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...)

@elamje
Copy link

elamje commented Jun 30, 2019

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

@PCManticore
Copy link
Contributor

@elamje This is as official as it gets: #1973 (comment)

@herrboyer
Copy link

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

@TaiwoAkinde
Copy link

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 !!!

@dxkaufman
Copy link

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...

@tb2johm
Copy link

tb2johm commented Oct 30, 2019

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

@lyzo
Copy link

lyzo commented Nov 21, 2019

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"]

@igorfarias30
Copy link

"pylint_flask_sqlalcheny" or "pylint_flask_sqlalchemy"?

@lyzo
Copy link

lyzo commented Dec 8, 2019

"pylint_flask_sqlalcheny" or "pylint_flask_sqlalchemy"?

pylint_flask_sqlalchemy, little typo :-)

@btoconnor
Copy link

@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]

@herrboyer
Copy link

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)

@silasechegini
Copy link

@YoungWilliamZ
thanks that worked for me as well.

@hudsonrb92
Copy link

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?

@hudsonrb92
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Won't fix/not planned
Projects
None yet
Development

No branches or pull requests