python
runtime_error
ai_generated
true
无法在 Python 中评估当前条件。请为 synchronize_session 参数指定 'fetch' 或 False。
sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.
ID: python/sqlalchemy-unhashable-condition
80%修复率
85%置信度
0证据数
2024-11-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在批量更新/删除中使用复杂表达式,SQLAlchemy 无法在会话中评估,尤其使用特定数据库函数时。
English
Using a bulk update/delete with a complex expression that SQLAlchemy cannot evaluate in the session, especially with certain database-specific functions.
解决方案
-
95% 成功率
session.query(User).filter(User.age > 30).update({'active': False}, synchronize_session=False) -
90% 成功率
session.query(User).filter(User.age > 30).update({'active': False}, synchronize_session='fetch')
无效尝试
常见但无效的做法:
-
50% 失败
Default is 'auto' which may still fail for complex criteria.
-
30% 失败
May bypass ORM features but not always desired.