From: Jan Vollmer Date: Wed, 22 Nov 2023 17:50:14 +0000 (+0100) Subject: Fixes: #10668 add local column to dependency rule error message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7f9952b81394d585e55dad6d6f355aaa54f599e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes: #10668 add local column to dependency rule error message --- diff --git a/lib/sqlalchemy/orm/sync.py b/lib/sqlalchemy/orm/sync.py index 036c26dd6b..dbe8fb7a25 100644 --- a/lib/sqlalchemy/orm/sync.py +++ b/lib/sqlalchemy/orm/sync.py @@ -86,8 +86,9 @@ def clear(dest, dest_mapper, synchronize_pairs): not in orm_util._none_set ): raise AssertionError( - "Dependency rule tried to blank-out primary key " - "column '%s' on instance '%s'" % (r, orm_util.state_str(dest)) + f"Dependency rule on column '{l}' " + "tried to blank-out primary key " + f"column '{r}' on instance '{orm_util.state_str(dest)}'" ) try: dest_mapper._set_state_attr_by_column(dest, dest.dict, r, None) diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index d6b886be15..969196ad8c 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -1334,7 +1334,8 @@ class CompositeSelfRefFKTest(fixtures.MappedTest, AssertsCompiledSQL): # this happens assert_raises_message( AssertionError, - "Dependency rule tried to blank-out primary key column " + "Dependency rule on column 'employee_t.company_id' " + "tried to blank-out primary key column " "'employee_t.company_id'", sess.flush, ) @@ -1669,7 +1670,7 @@ class FKsAsPksTest(fixtures.MappedTest): assert_raises_message( AssertionError, - "Dependency rule tried to blank-out " + "Dependency rule on column 'tableA.id' tried to blank-out " "primary key column 'tableB.id' on instance ", sess.flush, ) @@ -1696,7 +1697,7 @@ class FKsAsPksTest(fixtures.MappedTest): b1.a = None assert_raises_message( AssertionError, - "Dependency rule tried to blank-out " + "Dependency rule on column 'tableA.id' tried to blank-out " "primary key column 'tableB.id' on instance ", sess.flush, ) diff --git a/test/orm/test_sync.py b/test/orm/test_sync.py index c8f511f447..10d73cb8d6 100644 --- a/test/orm/test_sync.py +++ b/test/orm/test_sync.py @@ -145,7 +145,7 @@ class SyncTest( eq_(b1.obj().__dict__["id"], 8) assert_raises_message( AssertionError, - "Dependency rule tried to blank-out primary key " + "Dependency rule on column 't1.id' tried to blank-out primary key " "column 't2.id' on instance '