1. Hajime Nakagami
  2. sqlalchemy

Commits

Mike Bayer  committed 1aa517b

Detection of a primary key change within the process
of cascading a natural primary key update will succeed
even if the key is composite and only some of the
attributes have changed.
[ticket:2665]

  • Participants
  • Parent commits c49d58e
  • Branches default

Comments (0)

Files changed (3)

File doc/build/changelog/changelog_08.rst

View file
  • Ignore whitespace
     :version: 0.8.0
 
     .. change::
+        :tags: bug, orm
+        :tickets: 2665
+
+      Detection of a primary key change within the process
+      of cascading a natural primary key update will succeed
+      even if the key is composite and only some of the
+      attributes have changed.
+
+    .. change::
         :tags: feature, orm
         :tickets: 2658
 

File lib/sqlalchemy/orm/sync.py

View file
  • Ignore whitespace
             _raise_col_to_prop(False, source_mapper, l, None, r)
         history = uowcommit.get_attribute_history(source, prop.key,
                                         attributes.PASSIVE_NO_INITIALIZE)
-        return bool(history.deleted)
+        if bool(history.deleted):
+            return True
     else:
         return False
 

File test/orm/test_sync.py

View file
  • Ignore whitespace
             True
         )
 
+    def test_source_modified_composite(self):
+        uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
+        a1.obj().foo = 10
+        a1._commit_all(a1.dict)
+        a1.obj().foo = 12
+        pairs = [(a_mapper.c.id, b_mapper.c.id,),
+                (a_mapper.c.foo, b_mapper.c.id)]
+        eq_(
+            sync.source_modified(uowcommit, a1, a_mapper, pairs),
+            True
+        )
+
+    def test_source_modified_composite_unmodified(self):
+        uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
+        a1.obj().foo = 10
+        a1._commit_all(a1.dict)
+        pairs = [(a_mapper.c.id, b_mapper.c.id,),
+                (a_mapper.c.foo, b_mapper.c.id)]
+        eq_(
+            sync.source_modified(uowcommit, a1, a_mapper, pairs),
+            False
+        )
+
     def test_source_modified_no_unmapped(self):
         uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
         pairs = [(b_mapper.c.id, b_mapper.c.id,)]