]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
hardening against inappropriate multi-table updates
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 Jun 2025 13:21:59 +0000 (09:21 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Jun 2025 14:19:48 +0000 (10:19 -0400)
commitdc0d0817622435ea46b33575fd4f84d3959dc42d
treeda4b096dd017deaeadd22f20ae9b3e602c847069
parentcbdc5b632c485fb695dd55e3a9d58b3ba35811ce
hardening against inappropriate multi-table updates

Hardening of the compiler's actions for UPDATE statements that access
multiple tables to report more specifically when tables or aliases are
referenced in the SET clause; on cases where the backend does not support
secondary tables in the SET clause, an explicit error is raised, and on the
MySQL or similar backends that support such a SET clause, more specific
checking for not-properly-included tables is performed.  Overall the change
is preventing these erroneous forms of UPDATE statements from being
compiled, whereas previously it was relied on the database to raise an
error, which was not always guaranteed to happen, or to be non-ambiguous,
due to cases where the parent table included the same column name as the
secondary table column being updated.

Fixed bug where the ORM would pull in the wrong column into an UPDATE when
a key name inside of the :meth:`.ValuesBase.values` method could be located
from an ORM entity mentioned in the statement, but where that ORM entity
was not the actual table that the statement was inserting or updating.  An
extra check for this edge case is added to avoid this problem.

Fixes: #12692
Change-Id: I342832b09dda7ed494caaad0cbb81b93fc10fe18
doc/build/changelog/unreleased_20/12692.rst [new file with mode: 0644]
lib/sqlalchemy/orm/bulk_persistence.py
lib/sqlalchemy/sql/crud.py
lib/sqlalchemy/sql/selectable.py
test/engine/test_reflection.py
test/orm/dml/test_bulk_statements.py
test/sql/test_update.py