diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-18 17:21:01 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-18 17:21:01 +0000 |
| commit | c48177f0fed3a43b3b8b02c18243cb1664ce0abb (patch) | |
| tree | 1b4e70a8e4d64059fff906533cf14b35b8845946 /lib/sqlalchemy/orm/unitofwork.py | |
| parent | bd04cffad83848e3edc5cb51c51ca6232270477a (diff) | |
| download | sqlalchemy-c48177f0fed3a43b3b8b02c18243cb1664ce0abb.tar.gz | |
- unit-of-work does a better check for "orphaned" objects that are
part of a "delete-orphan" cascade, for certain conditions where the
parent isnt available to cascade from.
- it is now invalid to declare a self-referential relationship with
"delete-orphan" (as the abovementioned check would make them impossible
to save)
- improved the check for objects being part of a session when the
unit of work seeks to flush() them as part of a relationship..
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
| -rw-r--r-- | lib/sqlalchemy/orm/unitofwork.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 33e0149e4..00d34a104 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -106,9 +106,10 @@ class UnitOfWork(object): pass def _validate_obj(self, obj): - if hasattr(obj, '_instance_key') and not self.identity_map.has_key(obj._instance_key): - raise InvalidRequestError("Instance '%s' is not attached or pending within this session" % repr(obj._instance_key)) - + if (hasattr(obj, '_instance_key') and not self.identity_map.has_key(obj._instance_key)) or \ + (not hasattr(obj, '_instance_key') and obj not in self.new): + raise InvalidRequestError("Instance '%s' is not attached or pending within this session" % repr(obj)) + def update(self, obj): """called to add an object to this UnitOfWork as though it were loaded from the DB, but is actually coming from somewhere else, like a web session or similar.""" @@ -184,7 +185,10 @@ class UnitOfWork(object): continue if obj in self.deleted: continue - flush_context.register_object(obj) + if object_mapper(obj)._is_orphan(obj): + flush_context.register_object(obj, isdelete=True) + else: + flush_context.register_object(obj) for obj in self.deleted: if objset is not None and not obj in objset: |
