]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed very stupid bug when deleting items with many-to-many
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Jun 2007 18:53:33 +0000 (18:53 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Jun 2007 18:53:33 +0000 (18:53 +0000)
uselist=False relations

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

diff --git a/CHANGES b/CHANGES
index 40f1f4e412b099056ae81d4c12bb647cc4f9fe2f..e60db5cb73581b558d33b9b23b072a59db328e68 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,8 @@
     - association proxies no longer bind tightly to source collections
       [ticket:597], and are constructed with a thunk instead
 - orm
+    - fixed very stupid bug when deleting items with many-to-many
+      uselist=False relations
     - remember all that stuff about polymorphic_union ?  for 
       joined table inheritance ?  Funny thing...
       You sort of don't need it for joined table inheritance, you 
index 0c0dacd2028a325db3be662f013fa55f2fe6b09a..54b043b322cfcf2692be879bbfbc188e72547763 100644 (file)
@@ -338,7 +338,7 @@ class ManyToManyDP(DependencyProcessor):
                 childlist = self.get_object_dependencies(obj, uowcommit, passive=self.passive_deletes)
                 if childlist is not None:
                     for child in childlist.deleted_items() + childlist.unchanged_items():
-                        if reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes:
+                        if child is None or (reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes):
                             continue
                         associationrow = {}
                         self._synchronize(obj, child, associationrow, False, uowcommit)
@@ -349,14 +349,14 @@ class ManyToManyDP(DependencyProcessor):
                 childlist = self.get_object_dependencies(obj, uowcommit)
                 if childlist is None: continue
                 for child in childlist.added_items():
-                    if reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes:
+                    if child is None or (reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes):
                         continue
                     associationrow = {}
                     self._synchronize(obj, child, associationrow, False, uowcommit)
                     uowcommit.attributes[(self, "manytomany", obj, child)] = True
                     secondary_insert.append(associationrow)
                 for child in childlist.deleted_items():
-                    if reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes:
+                    if child is None or (reverse_dep and (reverse_dep, "manytomany", child, obj) in uowcommit.attributes):
                         continue
                     associationrow = {}
                     self._synchronize(obj, child, associationrow, False, uowcommit)
index 62b1db8604124023a0bfc0f0b1569382e42a986c..bf40a49f705aafbd7e2541b01c412e6f864d6fd6 100644 (file)
@@ -1277,6 +1277,21 @@ class ManyToManyTest(UnitOfWorkTest):
         ctx.current.flush()
         assert itemkeywords.count().scalar() == 0
 
+    def testscalar(self):
+        """test that dependency.py doesnt try to delete an m2m relation referencing None."""
+        
+        mapper(Keyword, keywords)
+
+        mapper(Item, orderitems, properties = dict(
+                keyword = relation(Keyword, secondary=itemkeywords, uselist=False),
+            ))
+        
+        i = Item()
+        ctx.current.flush()
+        ctx.current.delete(i)
+        ctx.current.flush()
+        
+        
 
     def testmanytomanyupdate(self):
         """tests some history operations on a many to many"""