synchronize_session='auto' silently converts to 'evaluate' then raises at execution time when WHERE criteria are present in bulk UPDATE
#13172
Replies: 2 comments 1 reply
-
|
Hi, Please provide a script that dimosteate the issue when filing something as bug. Also please follow the issue template since it's there for a reason. |
Beta Was this translation helpful? Give feedback.
-
|
hi - im not sure this description is accurate. firstly, at https://docs.sqlalchemy.org/en/20/orm/queryguide/dml.html#selecting-a-synchronization-strategy we describe that "auto" defaults to "fetch" on all platforms that support "returning". that's for "orm enabled update and delete" which is what you are showing with secondly, "At execution time, not statement-construction time, an InvalidRequestError is raised", how come? the whole point of the "evaluate" feature is to evaluate WHERE criteria. why would it fail under normal circumstances? as mentioned in other issues, it looks like you are using an LLM to find source code issues. please instruct your LLM to prove its guesses by having it create a proof of concept script that shows the issue, in this case I think it will have some difficulty doing so. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In
lib/sqlalchemy/orm/bulk_persistence.py, the defaultsynchronize_session='auto'is automatically converted to'evaluate'for bulk operations (line 791). However,'evaluate'is then explicitly rejected when the UPDATE has additional WHERE criteria (lines 1642–1652):The result is:
session.query(Model).filter(Model.x == 1).update({...})— a completely ordinary patternsynchronize_sessiondefaults to'auto', which silently becomes'evaluate'InvalidRequestErroris raisedThis is a late-stage, opaque failure. The error message says "right now", implying a known limitation, but:
Query.update()andSession.execute()docs don't highlight this constraint under theautostrategyauto→evaluatehappens in one place (line 791) without a guard for WHERE criteriasynchronize_session=FalseorNoneQuestions:
autostrategy detect WHERE criteria at conversion time and choose'fetch'instead of'evaluate'in that case?evaluate+ WHERE combination is permanently unsupported, shouldautonever resolve toevaluatefor bulk UPDATEs?update()call time rather than execution time)?File:
lib/sqlalchemy/orm/bulk_persistence.py, lines 791, 1642–1652.Beta Was this translation helpful? Give feedback.
All reactions