]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug whereby "passive_deletes='all'" wasn't passing
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jan 2011 15:55:46 +0000 (10:55 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jan 2011 15:55:46 +0000 (10:55 -0500)
the correct symbols to lazy loaders during flush, thereby
causing an unwarranted load.  [ticket:2013]

CHANGES
lib/sqlalchemy/orm/dependency.py
lib/sqlalchemy/orm/unitofwork.py
test/orm/test_unitofwork.py

diff --git a/CHANGES b/CHANGES
index 6491cf7419da4fff823172d8a94fd0f63567aab3..65b403d4d135ddb1983f1afb7345f49a4c5b8051 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -29,6 +29,10 @@ CHANGES
     that weren't previously saved in the "mutable changes"
     dictionary.
 
+  - Fixed bug whereby "passive_deletes='all'" wasn't passing
+    the correct symbols to lazy loaders during flush, thereby
+    causing an unwarranted load.  [ticket:2013]
+
   - Fixed bug which prevented composite mapped
     attributes from being used on a mapped select statement. 
     [ticket:1997]. Note the workings of composite are slated to 
index 8acf77ad8d7fbafed2a6a2f65b683b78a7cae6e8..e3e2f5d567b1e5859ae7b219dfe346336d118b03 100644 (file)
@@ -26,6 +26,9 @@ class DependencyProcessor(object):
         self.passive_deletes = prop.passive_deletes
         self.passive_updates = prop.passive_updates
         self.enable_typechecks = prop.enable_typechecks
+        self._passive_delete_flag = self.passive_deletes and \
+                                    attributes.PASSIVE_NO_INITIALIZE or \
+                                    attributes.PASSIVE_OFF
         self.key = prop.key
         if not self.prop.synchronize_pairs:
             raise sa_exc.ArgumentError(
@@ -390,7 +393,7 @@ class OneToManyDP(DependencyProcessor):
             history = uowcommit.get_attribute_history(
                                             state, 
                                             self.key, 
-                                            passive=self.passive_deletes)
+                                            passive=self._passive_delete_flag)
             if history:
                 for child in history.deleted:
                     if child is not None and self.hasparent(child) is False:
@@ -466,7 +469,7 @@ class OneToManyDP(DependencyProcessor):
                 history = uowcommit.get_attribute_history(
                                             state, 
                                             self.key, 
-                                            passive=self.passive_deletes)
+                                            passive=self._passive_delete_flag)
                 if history:
                     for child in history.deleted:
                         if child is not None and \
@@ -646,7 +649,7 @@ class ManyToOneDP(DependencyProcessor):
                 history = uowcommit.get_attribute_history(
                                         state, 
                                         self.key, 
-                                        passive=self.passive_deletes)
+                                        passive=self._passive_delete_flag)
                 if history:
                     if self.cascade.delete_orphan:
                         todelete = history.sum()
@@ -669,7 +672,7 @@ class ManyToOneDP(DependencyProcessor):
                 history = uowcommit.get_attribute_history(
                                         state, 
                                         self.key, 
-                                        passive=self.passive_deletes)
+                                        passive=self._passive_delete_flag)
                 if history:
                     ret = True
                     for child in history.deleted:
@@ -697,7 +700,7 @@ class ManyToOneDP(DependencyProcessor):
                     history = uowcommit.get_attribute_history(
                                                 state, 
                                                 self.key, 
-                                                passive=self.passive_deletes)
+                                                passive=self._passive_delete_flag)
                     if history:
                         self._post_update(state, uowcommit, history.sum())
 
@@ -906,7 +909,7 @@ class ManyToManyDP(DependencyProcessor):
                 history = uowcommit.get_attribute_history(
                                         state, 
                                         self.key, 
-                                        passive=self.passive_deletes)
+                                        passive=self._passive_delete_flag)
 
     def presort_saves(self, uowcommit, states):
         if not self.passive_updates:
@@ -954,7 +957,7 @@ class ManyToManyDP(DependencyProcessor):
             history = uowcommit.get_attribute_history(
                                     state, 
                                     self.key, 
-                                    passive=self.passive_deletes)
+                                    passive=self._passive_delete_flag)
             if history:
                 for child in history.non_added():
                     if child is None or \
index f1c5fcfc680491c391a3612d351bce491c0e2ed0..07c9c2b6d69a64fc522bada3483dca2230db013a 100644 (file)
@@ -149,7 +149,7 @@ class UOWTransaction(object):
 
         self.states[state] = (isdelete, True)
 
-    def get_attribute_history(self, state, key, passive=True):
+    def get_attribute_history(self, state, key, passive=attributes.PASSIVE_NO_INITIALIZE):
         """facade to attributes.get_state_history(), including caching of results."""
 
         hashkey = ("history", state, key)
index d5cd4691620a1ac0f16768434a6136f521f013ad..0625b59c971e7373f707f810f9d6b3cfc2019beb 100644 (file)
@@ -561,16 +561,14 @@ class ExtraPassiveDeletesTest(_base.MappedTest):
     @testing.resolve_artifact_names
     def test_assertions(self):
         mapper(MyOtherClass, myothertable)
-        try:
-            mapper(MyClass, mytable, properties={
-                'children':relationship(MyOtherClass,
+        assert_raises_message(
+            sa.exc.ArgumentError,
+            "Can't set passive_deletes='all' in conjunction with 'delete' "
+            "or 'delete-orphan' cascade",
+            relationship, MyOtherClass,
                                     passive_deletes='all',
-                                    cascade="all")})
-            assert False
-        except sa.exc.ArgumentError, e:
-            eq_(str(e),
-                "Can't set passive_deletes='all' in conjunction with 'delete' "
-                "or 'delete-orphan' cascade")
+                                    cascade="all"
+        )
 
     @testing.resolve_artifact_names
     def test_extra_passive(self):
@@ -617,6 +615,23 @@ class ExtraPassiveDeletesTest(_base.MappedTest):
         mc.children[0].data = 'some new data'
         assert_raises(sa.exc.DBAPIError, session.flush)
 
+    @testing.resolve_artifact_names
+    def test_dont_emit(self):
+        mapper(MyOtherClass, myothertable)
+        mapper(MyClass, mytable, properties={
+            'children': relationship(MyOtherClass,
+                                 passive_deletes='all',
+                                 cascade="save-update")})
+        session = Session()
+        mc = MyClass()
+        session.add(mc)
+        session.commit()
+        mc.id
+
+        session.delete(mc)
+
+        # no load for "children" should occur
+        self.assert_sql_count(testing.db, session.flush, 1)
 
 class ColumnCollisionTest(_base.MappedTest):
     """Ensure the mapper doesn't break bind param naming rules on flush."""