python
runtime_error
ai_generated
true
sqlalchemy.exc.InvalidRequestError: This session is in 'expired' state. No further SQL can be emitted within this transaction.
ID: python/sqlalchemy-exc-invalid-request-session-expired
80%Fix Rate
83%Confidence
0Evidence
2025-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The session has been expired due to a rollback or close, and attempting to execute SQL on it raises this error.
generic中文
会话因回滚或关闭而过期,尝试对其执行 SQL 会引发此错误。
Workarounds
-
95% success Close and create new session
Close the expired session and create a new one: session.close(); session = Session()
-
80% success Start new transaction
Use session.begin() to start a new transaction if the session is still in a recoverable state.
Dead Ends
Common approaches that don't work:
- Using expire_all() to revive session 70% fail
- Creating new session without closing old 50% fail