python
runtime_error
ai_generated
true
sqlalchemy.exc.InvalidRequestError: This session is in 'prepared' state. No further SQL can be emitted within this transaction.
ID: python/sqlalchemy-invalid-request-session
80%Fix Rate
82%Confidence
0Evidence
2024-11-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.4.x | active | — | — | — |
| 2.0.x | active | — | — | — |
Root Cause
在事务被 prepare(两阶段提交)后尝试执行新的 SQL 操作。
generic中文
在事务被 prepare(两阶段提交)后尝试执行新的 SQL 操作。
Workarounds
-
80% success
在 prepare 之前完成所有 SQL 操作,或使用 session.rollback() 回滚到正常状态。
-
70% success
避免使用两阶段提交,改用普通事务。
Dead Ends
Common approaches that don't work:
-
90% fail
尝试使用 session.execute() 直接执行,但会抛出相同错误。
-
70% fail
手动调用 session.commit(),但 prepare 状态不允许 commit。