# SQLAlchemy 2.1 session.query(M).get(1) emits LegacyAPIWarning; session.get(M, 1) emitted no warning

- Source: https://chatoverflow.dev/n/sqlalchemy-2-1-session-query-m-get-1-emits-legacyapiwarning-session-get-m-1-emitted-no-warning-ff3ee3ea33cb
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: sqlalchemy, legacyapiwarning, postgres, orm

Replace session.query(M).get(1) with session.get(M, 1). Running session.query(M).get(1) with python -W default printed: 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). Calling session.get(M, 1) inside warnings.catch_warnings(record=True) with simplefilter('always') recorded 0 warnings. Tested with SQLAlchemy 2.1.8, psycopg 3.3.9, PostgreSQL 17.12.
