Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance of 'SQLAlchemy' has no 'Column' member (no-member)

I'm currently trying to implement steam login into website. But I'm unable to get pass this error within the code. I've created the database object but it keeps showing the error I mentioned earlier. I'm not sure whether SQLAlchemy has changed or what since I used it.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)

The message emitted by pylint is

E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
like image 293
Vice Kay Avatar asked Dec 30 '18 04:12

Vice Kay


5 Answers

EDIT: After read and try np8's answer my previous answer is wrong there is a package you have to install, which is pylint_flask_sqlalchemy

so the answer will be

on your project directory find folder .vscode (if you dont have it, just create it) then create file settings.json and add this line

{
    # You have to put it in this order to make it works
    "python.linting.pylintArgs": [
        "--load-plugins",
        "pylint_flask_sqlalchemy",
        "pylint_flask",                 # This package is optional
    ]
}

You also need to have pylint-flask-sqlalchemy and if you want to use pylint-flask install on your current python environment:

pip install pylint-flask-sqlalchemy
pip install pylint-flask
like image 174
Aditya Avatar answered Nov 17 '22 00:11

Aditya


pip install pylint-flask

In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json as below:

"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
like image 21
Ranjita Shetty Avatar answered Nov 17 '22 00:11

Ranjita Shetty


Summary of working and non-working configurations

It seems that this can be configured so many ways incorrectly, that I decided to write the different options down. I am assuming VS Code, but for command line or other editor, arguments and their order is the same. These were tested using the latest versions of all the packages (list in the bottom of this post)

Working versions

# What you'll need is pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]

# You can add pylint_flask but only if it is *AFTER* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]

Non-working versions

# pylint_flask does not help, but can break it (see below)
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]

# You can NOT add pylint_flask *BEFORE* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]

# CAUTION: These will disable pylint silently altogether!
# Do not use dash (-) but underscore (_)!
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy"]

Details for those who are interested

pylint_flask_sqlalchemy

The pylint-flask-sqlalchemy1 was created specifically to fix this2. You can enable it by adding it to --load-plugins of pylint. In command line this would be

python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>

and in VS Code (Settings (JSON)):

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

1Also mirrored to GitHub: https://github.com/anybox/pylint_flask_sqlalchemy
2See this comment on pylint Issue tracker.

pylint_flask

pylint-flask is pylint plugin for Flask. It has nothing to do with Flask-SQLAlchemy and it does not even try to solve the false positive issues pylint has with Flask-SQLAlchemy3. The only possibility to use pylint-flask to "make the errors disappear" is to load it with erroneusly with dashes, which makes the whole pylint to be disabled.

It seems that pylint-flask must be loaded after pylint-flas-sqlalchemy; I tested with my setup, and for some reason

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

will not work, but

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

will. So the order of loading plugins matters.

3 See the code for yourself: pylint-flask source & pylint-flask-sqlaclhemy source

Caution: Do not remove your linting accidentally

As the documentation of pylint-flask and pylint-flask-sqlalchemy says, the names in the argument --load-plugins should be written with underscores; If you use

"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]

in VS Code, the errors will be gone, but so will be all of your linting as the pylint crashes silently in the background.

Installing pylint-flask-sqlalchemy

pip install pylint-flask-sqlalchemy

Used versions

Flask                   1.1.2  
Flask-SQLAlchemy        2.4.4 
pylint                  2.5.3
pylint-flask            0.6
pylint-flask-sqlalchemy 0.2.0

See also

  • Discussion on pylint GitHub issue: "Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object."
like image 20
np8 Avatar answered Nov 17 '22 00:11

np8


Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:

Python: Select Linter

Switch from PyLint to flake8 or other supported linters.

like image 18
fill_J Avatar answered Nov 16 '22 23:11

fill_J


I've just encountered this issue. Neither of the suggested solutions worked for me, but the following does.

First, install these modules:

pip install pylint-flask
pip install pylint-flask-sqlalchemy

Then, in Visual Studio Code, you need to add the following to your settings.json file:

"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
like image 13
Venemo Avatar answered Nov 17 '22 01:11

Venemo