]> 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:55 +0000 (10:19 -0400)
commitf1b6be1bd8881ce52d72e2fefb5446bf675e18f0
tree89035fe879e266d00b9753cf9ce20f5ea278f183
parent8826e0d9756443367ad9b15bb40286da9fe5d8c8
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
(cherry picked from commit dc0d0817622435ea46b33575fd4f84d3959dc42d)
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