pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Bug: SQLAlchemy intellisense does not autocomplete for ORM. For example "db.Model.Integer"

Open animehunter123 opened this issue 2 years ago • 1 comments

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: output

I think it is because Intellisense doesnt do ORM python autocompletion like other editors (ATOM does do this correctly).

animehunter123 avatar Aug 26 '22 06:08 animehunter123

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?

heejaechang avatar Aug 30 '22 19:08 heejaechang

Closing old issue. If this is still a problem, please reopen with the information requested. thanks

judej avatar Nov 02 '22 19:11 judej

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.

auroraostrovica avatar Dec 20 '23 14:12 auroraostrovica