From 85156a0fbe43f8691e19c077c92b0d433f9e654b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 3 Apr 2010 18:24:04 -0400 Subject: [PATCH] got row switch more or less up --- lib/sqlalchemy/orm/mapper.py | 6 +++--- lib/sqlalchemy/orm/unitofwork.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 22b5e5177a..319b061586 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1340,8 +1340,8 @@ class Mapper(object): if not postupdate: for state, mapper, connection, has_identity, instance_key in tups: # detect if we have a "pending" instance (i.e. has no instance_key attached to it), - # and another instance with the same identity key already exists as persistent. convert to an - # UPDATE if so. + # and another instance with the same identity key already exists as persistent. + # convert to an UPDATE if so. if not has_identity and instance_key in uowtransaction.session.identity_map: instance = uowtransaction.session.identity_map[instance_key] existing = attributes.instance_state(instance) @@ -1356,7 +1356,7 @@ class Mapper(object): "transaction", instance_key, state_str(state), state_str(existing)) # remove the "delete" flag from the existing element - uowtransaction.set_row_switch(existing) + uowtransaction.remove_state_actions(existing) row_switches[state] = existing table_to_mapper = self._sorted_tables diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index ceed4c2885..a4eb00f70a 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -101,6 +101,19 @@ class UOWTransaction(object): def is_deleted(self, state): """return true if the given state is marked as deleted within this UOWTransaction.""" return state in self.states and self.states[state][0] + + def remove_state_actions(self, state): + """remove pending actions for a state from the uowtransaction.""" + + if state in self.states: + isdelete, listonly = self.states[state] + self.states[state] = (False, True) + if isdelete: + self.postsort_actions.pop((DeleteState, state), None) + else: + self.postsort_actions.pop((SaveUpdateState, state), None) + + def get_attribute_history(self, state, key, passive=True): hashkey = ("history", state, key) -- 2.47.3