summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-07-24 10:10:28 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-07-24 10:10:28 -0400
commit8e0618aa650c43b483dbae443ddca94fcdd5b945 (patch)
tree5afa12ff20e2c05aae2f379beb26832077987254 /lib/sqlalchemy
parentca9029ca9830573c4a5618e5dc01347576d50eb4 (diff)
downloadsqlalchemy-8e0618aa650c43b483dbae443ddca94fcdd5b945.tar.gz
- 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
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/mapper.py35
1 files changed, 23 insertions, 12 deletions
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)