python runtime_error ai_generated true

此会话处于“已提交”状态。无法在此事务中发出更多 SQL。

sqlalchemy.exc.InvalidRequestError: This session is in 'committed' state. No further SQL can be emitted within this transaction.

ID: python/sqlalchemy-invalid-request-session-committed

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-04-10首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

在会话已提交后尝试执行 SQL 语句,这会结束当前事务。

English

Attempting to execute SQL statements after the session has already been committed, which ends the current transaction.

generic

解决方案

  1. 90% 成功率 Start a new transaction with session.begin()
    Use session.begin() to start a new transaction explicitly after commit, or use session.close() and create a fresh session.
  2. 95% 成功率 Use context manager for transaction
    Refactor code to perform all SQL operations within a single transaction block using 'with session.begin():'.

无效尝试

常见但无效的做法:

  1. Calling session.rollback() after commit 80% 失败

  2. Creating a new session without closing the old one 50% 失败