diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-11-23 05:24:32 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-11-23 05:24:32 +0000 |
commit | 41403b79300fb65125ab8bde00efbec9eaa89d43 (patch) | |
tree | 5d4e41b95b84c0a63ec178eb647bcd698bdcd51c /lib/sqlalchemy | |
parent | 56d14df0ebce6055356ea090cffe1b9ee91d592c (diff) | |
download | sqlalchemy-41403b79300fb65125ab8bde00efbec9eaa89d43.tar.gz |
- some clarifications and fixes to merge(instance, dont_load=True).
fixed bug where lazy loaders were getting disabled on returned instances.
Also, we currently do not support merging an instance which has uncommitted
changes on it, in the case that dont_load=True is used....this will
now raise an error. This is due to complexities in merging the
"committed state" of the given instance to correctly correspond to the
newly copied instance. Since the use case for dont_load=True is
caching, the given instances shouldn't have any uncommitted changes on them
anyway.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 100727520..b04c62c7b 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -881,10 +881,13 @@ class Session(object): if key in self.identity_map: merged = self.identity_map[key] elif dont_load: + if object._state.modified: + raise exceptions.InvalidRequestError("merge() with dont_load=True option does not support objects marked as 'dirty'. flush() all changes on mapped instances before merging with dont_load=True.") + merged = attribute_manager.new_instance(mapper.class_) merged._instance_key = key + merged._entity_name = entity_name self._update_impl(merged, entity_name=mapper.entity_name) - merged._state.committed_state = object._state.committed_state.copy() else: merged = self.get(mapper.class_, key[1]) if merged is None: @@ -894,6 +897,8 @@ class Session(object): prop.merge(self, object, merged, dont_load, _recursive) if key is None: self.save(merged, entity_name=mapper.entity_name) + elif dont_load: + merged._state.commit_all() return merged def identity_key(cls, *args, **kwargs): |