pylance-release
pylance-release copied to clipboard
Bug: SQLAlchemy intellisense does not autocomplete for ORM. For example "db.Model.Integer"
Hello,
This issue appears occurs in the latest version of VSCode on Win10.
Vscode does not appear to autocomplete methods from SQLAlchemy (and maybe other Python ORM modules as well). (This issue was improperly closed from: https://github.com/Microsoft/vscode-python/issues/292 and there is no fix).
Example Python Code to demonstrate:
@@@File: flask-sqlalchemy-test-app.py@@@
# ORM model class:
class TestModel(db.Model):
id = db.Column(db.Integer,primary_key=True)
name = db. <---- When you press 'dot' here, the Intellisense Autocomplete does not show "db.Column"
Demonstration of Bug:
I think it is because Intellisense doesnt do ORM python autocompletion like other editors (ATOM does do this correctly).
Column is not there since it is dynamically added to the SQlAchemy db instance in here - https://github.com/pallets-eco/flask-sqlalchemy/blob/main/src/flask_sqlalchemy/init.py#L765 which does this https://github.com/pallets-eco/flask-sqlalchemy/blob/main/src/flask_sqlalchemy/init.py#L103
basically, the code dynamically add all top level symbols of sqlalchemy, sqlalchemy.orm under db instance. currently we don't support such dynamic behaviors. (in other words, something that requires running python code)
the ATOM you referring. do they actually run the python code to provide auto complete? can you provide more detail so we can take a look?
Closing old issue. If this is still a problem, please reopen with the information requested. thanks
In my experience, the most effective solution for flask sqlalchemy autocomplete is by installing flask-sqlalchemy-stubs package, a method I've found to be particularly insightful.
If this resolves your issue, feel free to explore concise solutions through my book https://pythonalliance.gumroad.com/l/ayuze where you can uncover efficient one line fixes.