summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-06-20 18:53:33 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-06-20 18:53:33 +0000
commit33648e71763d415bf17ea94e4066ea0adccca11a (patch)
tree7b5b9dfa6f291a0325a535e10d1f490c8ac65e2a
parent2e72d7e15ff6565d105659a34da5b03691513f4b (diff)
downloadsqlalchemy-33648e71763d415bf17ea94e4066ea0adccca11a.tar.gz
- fixed very stupid bug when deleting items with many-to-many
uselist=False relations
-rw-r--r--CHANGES2
-rw-r--r--lib/sqlalchemy/orm/dependency.py6
-rw-r--r--test/orm/unitofwork.py15
3 files changed, 20 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 40f1f4e41..e60db5cb7 100644
--- 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
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py
index 0c0dacd20..54b043b32 100644
--- a/lib/sqlalchemy/orm/dependency.py
+++ b/lib/sqlalchemy/orm/dependency.py
@@ -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)
diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py
index 62b1db860..bf40a49f7 100644
--- a/test/orm/unitofwork.py
+++ b/test/orm/unitofwork.py
@@ -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"""