From: Mike Bayer Date: Mon, 25 Feb 2013 23:55:09 +0000 (-0500) Subject: Detection of a primary key change within the process X-Git-Tag: rel_0_8_0~17^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95297c35442e483bb98b5a4edb677bb168064f5e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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] --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 8951217ffb..89fcd87d05 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -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 diff --git a/lib/sqlalchemy/orm/sync.py b/lib/sqlalchemy/orm/sync.py index b386a65319..6524ab27af 100644 --- a/lib/sqlalchemy/orm/sync.py +++ b/lib/sqlalchemy/orm/sync.py @@ -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 diff --git a/test/orm/test_sync.py b/test/orm/test_sync.py index a2c894725c..c5825e88b6 100644 --- a/test/orm/test_sync.py +++ b/test/orm/test_sync.py @@ -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,)]