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
--- /dev/null
+.. 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.
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)
# 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,
)
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,
)
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,
)
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,