summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-03-31 14:57:19 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-03-31 14:57:19 +0000
commit832ea82fefa366f4717e889511f66ecfce3313de (patch)
tree0edb6b2ea2f3b4fd8580c48af93286a8806f11da /lib/sqlalchemy/orm/session.py
parentaca84bebb091a51ceeb911249c366e17b954826a (diff)
downloadsqlalchemy-832ea82fefa366f4717e889511f66ecfce3313de.tar.gz
- Fixed another location where autoflush was interfering
with session.merge(). autoflush is disabled completely for the duration of merge() now. [ticket:1360]
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index d8af4e74f..954b31310 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1141,8 +1141,7 @@ class Session(object):
for state, m, o in cascade_states:
self._delete_impl(state)
- def merge(self, instance, dont_load=False,
- _recursive=None):
+ def merge(self, instance, dont_load=False):
"""Copy the state an instance onto the persistent instance with the same identifier.
If there is no persistent instance currently associated with the
@@ -1155,13 +1154,18 @@ class Session(object):
mapped with ``cascade="merge"``.
"""
- if _recursive is None:
- # TODO: this should be an IdentityDict for instances, but will
- # need a separate dict for PropertyLoader tuples
- _recursive = {}
- # Autoflush only on the topmost call
- self._autoflush()
-
+ # TODO: this should be an IdentityDict for instances, but will
+ # need a separate dict for PropertyLoader tuples
+ _recursive = {}
+ self._autoflush()
+ autoflush = self.autoflush
+ try:
+ self.autoflush = False
+ return self._merge(instance, dont_load=dont_load, _recursive=_recursive)
+ finally:
+ self.autoflush = autoflush
+
+ def _merge(self, instance, dont_load=False, _recursive=None):
mapper = _object_mapper(instance)
if instance in _recursive:
return _recursive[instance]
@@ -1169,6 +1173,7 @@ class Session(object):
new_instance = False
state = attributes.instance_state(instance)
key = state.key
+
if key is None:
if dont_load:
raise sa_exc.InvalidRequestError(
@@ -1194,7 +1199,7 @@ class Session(object):
self._update_impl(merged_state)
new_instance = True
else:
- merged = self.query(mapper.class_).autoflush(False).get(key[1])
+ merged = self.query(mapper.class_).get(key[1])
if merged is None:
merged = mapper.class_manager.new_instance()