]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Refined bulk-assignment aspects of the r3999 in-place collection operator fix. Also...
authorJason Kirtland <jek@discorporate.us>
Fri, 4 Jan 2008 20:40:22 +0000 (20:40 +0000)
committerJason Kirtland <jek@discorporate.us>
Fri, 4 Jan 2008 20:40:22 +0000 (20:40 +0000)
lib/sqlalchemy/orm/attributes.py
test/orm/collection.py

index 0937568e2fa7539e058b6d840cae3fbd349a5f05..21b8a4e641933a4efdd048a16e53b9e148cbd6c0 100644 (file)
@@ -532,8 +532,14 @@ class CollectionAttributeImpl(AttributeImpl):
         new_values = list(new_collection.adapt_like_to_iterable(value))
 
         old = self.get(state)
+
+        # ignore re-assignment of the current collection, as happens
+        # implicitly with in-place operators (foo.collection |= other)
+        if old is value:
+            return
+
         state.committed_state[self.key] = self.copy(old)
-        
+
         old_collection = self.get_collection(state, old)
 
         idset = util.IdentitySet
index 6e50a85125fea11db59db98ecbd181f7d0406f5c..fb4dbf199c1251503a01d45d5b494dd809898d17 100644 (file)
@@ -443,6 +443,12 @@ class CollectionsTest(PersistTest):
             control |= values
             assert_eq()
 
+            # cover self-assignment short-circuit
+            values = set([e, creator(), creator()])
+            obj.attr |= values
+            control |= values
+            assert_eq()
+
             try:
                 direct |= [e, creator()]
                 assert False
@@ -483,6 +489,11 @@ class CollectionsTest(PersistTest):
             control -= values
             assert_eq()
 
+            values = set([creator()])
+            obj.attr -= values
+            control -= values
+            assert_eq()
+
             try:
                 direct -= [e, creator()]
                 assert False
@@ -519,6 +530,11 @@ class CollectionsTest(PersistTest):
             control &= values
             assert_eq()
 
+            values.update(set([creator()]))
+            obj.attr &= values
+            control &= values
+            assert_eq()
+
             try:
                 direct &= [e, creator()]
                 assert False
@@ -569,6 +585,11 @@ class CollectionsTest(PersistTest):
             control ^= values
             assert_eq()
 
+            values = set([creator()])
+            obj.attr ^= values
+            control ^= values
+            assert_eq()
+
             try:
                 direct ^= [e, creator()]
                 assert False