From 8e0618aa650c43b483dbae443ddca94fcdd5b945 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 24 Jul 2010 10:10:28 -0400 Subject: - The value of version_id_col can be changed manually, and this will result in an UPDATE of the row. Versioned UPDATEs and DELETEs now use the "committed" value of the version_id_col in the WHERE clause and not the pending changed value. The version generator is also bypassed if manual changes are present on the attribute. [ticket:1857] - ensure before_update/after_update called on parent for collection change --- lib/sqlalchemy/orm/mapper.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 89de7b91b..6c25b89ca 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1690,24 +1690,35 @@ class Mapper(object): for col in mapper._cols_by_table[table]: if col is mapper.version_id_col: params[col._label] = \ - mapper._get_state_attr_by_column( + mapper._get_committed_state_attr_by_column( row_switch or state, row_switch and row_switch.dict or state_dict, col) - params[col.key] = \ + + prop = mapper._columntoproperty[col] + history = attributes.get_state_history( + state, prop.key, passive=True + ) + if history.added: + params[col.key] = history.added[0] + hasdata = True + else: + params[col.key] = \ mapper.version_id_generator( params[col._label]) - # HACK: check for history, in case the - # history is only - # in a different table than the one - # where the version_id_col is. - for prop in mapper._columntoproperty.itervalues(): - history = attributes.get_state_history( - state, prop.key, passive=True) - if history.added: - hasdata = True + # HACK: check for history, in case the + # history is only + # in a different table than the one + # where the version_id_col is. + for prop in mapper._columntoproperty.\ + itervalues(): + history = attributes.get_state_history( + state, prop.key, + passive=True) + if history.added: + hasdata = True elif mapper.polymorphic_on is not None and \ mapper.polymorphic_on.shares_lineage(col) and \ col not in pks: @@ -1985,7 +1996,7 @@ class Mapper(object): if mapper.version_id_col is not None and \ table.c.contains_column(mapper.version_id_col): params[mapper.version_id_col.key] = \ - mapper._get_state_attr_by_column( + mapper._get_committed_state_attr_by_column( state, state_dict, mapper.version_id_col) -- cgit v1.2.1