]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Detection of a primary key change within the process
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 25 Feb 2013 23:55:09 +0000 (18:55 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 25 Feb 2013 23:55:09 +0000 (18:55 -0500)
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]

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/orm/sync.py
test/orm/test_sync.py

index 8951217ffb8bffef5f5d9714dc59d92418a91869..89fcd87d05a82a0a288ab8ec25774521b7ef9005 100644 (file)
@@ -6,6 +6,15 @@
 .. changelog::
     :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
index b386a65319c6ac772045ab0cc0babd3c21e2d032..6524ab27afe23e4ee417d8144cb6497e354230d3 100644 (file)
@@ -94,7 +94,8 @@ def source_modified(uowcommit, source, source_mapper, synchronize_pairs):
             _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
 
index a2c894725ca247b611ac82477cda8d3166b77722..c5825e88b60f82b7bedc35e4893c8fe293d88197 100644 (file)
@@ -212,6 +212,29 @@ class SyncTest(fixtures.MappedTest,
             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,)]