inconsistent treatment of collection flushes

Issue #1973 resolved
Mike Bayer repo owner created an issue

consider generating a suite of tests for collection append/delete where the target is not present in the session. establish consistent behavior for o2m and m2m, or at least cover it. This will probably be pushed to 0.7 since it implies a behavioral change.

diff -r d3ca4156495af556e448a8d3f6d5884d08ab2f9b lib/sqlalchemy/orm/dependency.py
--- a/lib/sqlalchemy/orm/dependency.py  Wed Nov 17 10:55:10 2010 -0500
+++ b/lib/sqlalchemy/orm/dependency.py  Wed Nov 17 15:36:36 2010 -0500
@@ -903,7 +903,7 @@

         if not self.cascade.delete_orphan:
             return
-        
+
         # check for child items removed from the collection
         # if delete_orphan check is turned on.
         for state in states:
@@ -975,7 +975,8 @@
                 for child in history.added:
                     if child is None or \
                             (processed is not None and 
-                                (state, child) in processed):
+                                # WHY NOT HERE ?
+                                (state, child) in processed) :
                         continue
                     associationrow = {}
                     self._synchronize(state, 
@@ -987,7 +988,11 @@
                     if child is None or \
                             (processed is not None and 
                             (state, child) in processed) or \
-                            not uowcommit.session._contains_state(child):
+                            (
+                                # ...BUT HERE ?  ALSO NO TEST COVERAGE !
+                                # HOW ABOUT O2M ?
+                                not uowcommit.session._contains_state(child):
+                            )
                         continue
                     associationrow = {}
                     self._synchronize(state,

Comments (4)

  1. Mike Bayer reporter
    • changed milestone to 0.7.0

    in the case of o2m, the target item requires the INSERT/UPDATE, so isn't in the session and is ignored. For consistency we should go with as few operations proceeding as possible for items not in the session. The attached patch is an experimental approach that emits warnings every time an object is ignored.

  2. Log in to comment