pallets-eco / flask-sqlalchemy

Adds SQLAlchemy support to Flask
https://flask-sqlalchemy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
4.22k stars 899 forks source link

ImportError: cannot import name '_QueryProperty' from 'flask_sqlalchemy' #1307

Closed fatjan closed 8 months ago

fatjan commented 8 months ago

I am using Flask-SQLAlchemy version 3.1.1 and I have the following import error issue:

ImportError: cannot import name '_QueryProperty' from 'flask_sqlalchemy'

File "/Users/user/.pyenv/versions/3.9.16/lib/python3.9/site-packages/flask_appbuilder/models/sqla/__init__.py", line 5, in <module>

Screenshot 2024-01-30 at 12 17 52

Replicate: use Flask-SQLAlchemy version 3.1.1 in a Flask app

Expected behaviour: the _QueryProperty should be successfully imported from flask_sqlalchemy without any issue

Environment:

davidism commented 8 months ago

That's no longer available, as the internal API has changed significantly in version 3. It was not marked as part of the public API. Note that the query API is considered legacy in SQLAlchemy 2, and you should migrate to its new execution API when possible. SQLAlchemy also provides it directly: https://docs.sqlalchemy.org/en/20/orm/contextual.html#sqlalchemy.orm.scoped_session.query_property