Commits

jason kirtland  committed f8bdf50

Refined bulk-assignment aspects of the r3999 in-place collection operator fix. Also? r4000!

  • Participants
  • Parent commits d4f4399

Comments (0)

Files changed (2)

File lib/sqlalchemy/orm/attributes.py

         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

File test/orm/collection.py

             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
             control -= values
             assert_eq()
 
+            values = set([creator()])
+            obj.attr -= values
+            control -= values
+            assert_eq()
+
             try:
                 direct -= [e, creator()]
                 assert False
             control &= values
             assert_eq()
 
+            values.update(set([creator()]))
+            obj.attr &= values
+            control &= values
+            assert_eq()
+
             try:
                 direct &= [e, creator()]
                 assert False
             control ^= values
             assert_eq()
 
+            values = set([creator()])
+            obj.attr ^= values
+            control ^= values
+            assert_eq()
+
             try:
                 direct ^= [e, creator()]
                 assert False