`Query.get_or_404()` triggers deprecation warning under SQLAlchemy 2.x
### **Description**
When using Flask-SQLAlchemy 3.x with SQLAlchemy 2.x, calling `Query.get_or_404()` produces a deprecation warning indicating that `Query.get()` is considered legacy. The warning points to the internal use of `Query.get()` within `get_or_404()`.
### **Steps to Reproduce**
1. Use SQLAlchemy 2.x and Flask-SQLAlchemy 3.x.
2. Define a simple model and call:
```python
user = User.query.get_or_404(1)
```
3. Observe the warning in the console or test output.
### **Observed Warning**
```
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().
(Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
```
### **Expected Behavior**
`get_or_404()` should not emit any deprecation warnings when running under SQLAlchemy 2.x.
### **Environment**
- Python version: 3.12
- Flask-SQLAlchemy version: 3.1.1
- SQLAlchemy version: 2.0.44
关闭于 2025-11-01 1 条评论