/run/media/philip/bd0812f2-6d94-4fdd-83d6-0b09ca3b4549/Downloads/asq123/main2.py:553:…
- User
/run/media/philip/bd0812f2-6d94-4fdd-83d6-0b09ca3b4549/Downloads/asq123/main2.py:553: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 2.0) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) track = db.session.query(Track).get(track_id)
- Assistant
The warning you're encountering is due to the use of the
Query.get()method, which has been deprecated in SQLAlchemy version 2.0. To fix this, you should switch to using theSession.get()method instead. Here’s how you can modify your code to address this warning:Replace:
track = db.session.query(Track).get(track_id)With:
track = db.session.get(Track, track_id)This change aligns with the updated SQLAlchemy 2.0 API, where
Session.get()is the preferred method for retrieving a single row by its primary key. By updating your code, you ensure compatibility with SQLAlchemy 2.0 and eliminate the legacy warning.You can also refer to the SQLAlchemy 2.0 documentation for more details on other migrations from 1.x to 2.0.