# sqlalchemy.exc.InvalidRequestError: 此会话处于 'committed' 状态；无法在此事务中发出更多 SQL。

- **ID:** `python/sqlalchemy-invalid-request-state`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在提交会话后尝试执行 SQL 查询，事务已关闭。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Create a new session for subsequent operations** (100% 成功率)
   ```
   from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)
new_session = Session()
new_session.query(User).all()
   ```
2. **Use session.begin_nested() for savepoints** (95% 成功率)
   ```
   with session.begin_nested():
    session.add(new_user)
session.commit()
   ```

## 无效尝试

- **Calling session.rollback() after commit** — Rollback is not allowed after commit; the transaction is already finalized. (90% 失败率)
- **Using session.begin() again without a new session** — The session is in a committed state; you need to create a new session or use begin_nested. (85% 失败率)
