summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-06-24 21:53:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-06-24 21:53:15 -0400
commit1e2f1f5baabd4ec8866ec19b586bb493ea099852 (patch)
tree73ecc79079315d2e86cbdc0ebffba0f8a48eeada /lib
parent00656ae4930620bc8c0c4be6a82853f01c90f758 (diff)
downloadsqlalchemy-1e2f1f5baabd4ec8866ec19b586bb493ea099852.tar.gz
- Fixed a major regression in the 1.0 series where the version_id_counter
feature would cause an object's version counter to be incremented when there was no net change to the object's row, but instead an object related to it via relationship (e.g. typically many-to-one) were associated or de-associated with it, resulting in an UPDATE statement that updates the object's version counter and nothing else. In the use case where the relatively recent "server side" and/or "programmatic/conditional" version counter feature were used (e.g. setting version_id_generator to False), the bug could cause an UPDATE without a valid SET clause to be emitted. fixes #3465
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/persistence.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index a42ed2f7c..4f074df8e 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -461,6 +461,23 @@ def _collect_update_commands(
if update_version_id is not None and \
mapper.version_id_col in mapper._cols_by_table[table]:
+
+ if not bulk and not (params or value_params):
+ # HACK: check for history in other tables, in case the
+ # history is only in a different table than the one
+ # where the version_id_col is. This logic was lost
+ # from 0.9 -> 1.0.0 and restored in 1.0.6.
+ for prop in mapper._columntoproperty.values():
+ history = (
+ state.manager[prop.key].impl.get_history(
+ state, state_dict,
+ attributes.PASSIVE_NO_INITIALIZE))
+ if history.added:
+ break
+ else:
+ # no net change, break
+ continue
+
col = mapper.version_id_col
params[col._label] = update_version_id
@@ -469,7 +486,7 @@ def _collect_update_commands(
val = mapper.version_id_generator(update_version_id)
params[col.key] = val
- if not (params or value_params):
+ elif not (params or value_params):
continue
if bulk: