As part of the Flask 3 / SQLAlchemy 2.x upgrade (#1098), Model.query is deprecated in Flask-SQLAlchemy 3.x and will be removed in a future version. Query.get() is also deprecated in SA 2.x in favour of db.session.get(). Both currently still work but emit deprecation warnings.
Scope
~62 production call sites across:
compair/api/ — answer.py, assignment.py, classlist.py, comparison.py, gradebook.py, impersonation.py, lti_launch.py, lti_course.py, login.py, report.py, users.py
compair/models/ — comparison.py, assignment_grade.py, answer_score.py, and others
compair/manage/
~85 test-side usages in compair/tests/api/
Migration pattern
Before
answers = Answer.query.filter_by(assignment_id=assignment.id).all()
After
answers = db.session.execute(
select(Answer).where(Answer.assignment_id == assignment.id)
).scalars().all()
with_entities() calls also go away naturally in this sweep — columns move into the select() argument list.
Query.get() specifically
Before
assignment = Assignment.query.get(assignment_id)
After
assignment = db.session.get(Assignment, assignment_id)
References
As part of the Flask 3 / SQLAlchemy 2.x upgrade (#1098),
Model.queryis deprecated in Flask-SQLAlchemy 3.x and will be removed in a future version.Query.get()is also deprecated in SA 2.x in favour ofdb.session.get(). Both currently still work but emit deprecation warnings.Scope
~62 production call sites across:
compair/api/— answer.py, assignment.py, classlist.py, comparison.py, gradebook.py, impersonation.py, lti_launch.py, lti_course.py, login.py, report.py, users.pycompair/models/— comparison.py, assignment_grade.py, answer_score.py, and otherscompair/manage/~85 test-side usages in
compair/tests/api/Migration pattern
Before
After
with_entities()calls also go away naturally in this sweep — columns move into the select() argument list.Query.get()specificallyBefore
After
References