]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add local column to dependency rule error message
authorJan Vollmer <jan@vllmr.dev>
Wed, 22 Nov 2023 18:16:27 +0000 (13:16 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Nov 2023 19:37:03 +0000 (14:37 -0500)
Improved the error message produced when the unit of work process sets the
value of a primary key column to NULL due to a related object with a
dependency rule on that column being deleted, to include not just the
destination object and column name but also the source column from which
the NULL value is originating.  Pull request courtesy Jan Vollmer.

Fixes: #10668
Closes: #10669
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10669
Pull-request-sha: d7f9952b81394d585e55dad6d6f355aaa54f599e

Change-Id: I210317f8777ff07d9eec674b79f2140523af38d0

doc/build/changelog/unreleased_20/10668.rst [new file with mode: 0644]
lib/sqlalchemy/orm/sync.py
test/orm/test_relationships.py
test/orm/test_sync.py

diff --git a/doc/build/changelog/unreleased_20/10668.rst b/doc/build/changelog/unreleased_20/10668.rst
new file mode 100644 (file)
index 0000000..560aac8
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, orm
+    :tickets: 10668
+
+    Improved the error message produced when the unit of work process sets the
+    value of a primary key column to NULL due to a related object with a
+    dependency rule on that column being deleted, to include not just the
+    destination object and column name but also the source column from which
+    the NULL value is originating.  Pull request courtesy Jan Vollmer.
index 036c26dd6bece9ba615d377ee50ef9b51a158747..dbe8fb7a251aa39a6d182ce53027912acd072733 100644 (file)
@@ -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)
index d6b886be151b1dc246f3306160940b08cfbdd1ab..969196ad8ca8a853074bf0088f6714b54d21d78c 100644 (file)
@@ -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,
             )
index c8f511f447a47125f120fae1dda3b2280f2e11f4..10d73cb8d6404a8644b57c3894dcf4dfa355c070 100644 (file)
@@ -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 '<B",
             sync.clear,
             b1,