]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
filter_by works across multiple entities
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Nov 2025 15:41:40 +0000 (10:41 -0500)
committerMichael Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Dec 2025 13:53:27 +0000 (13:53 +0000)
commit9a0d00433134b44a132104618b96516e47fff224
treecae7a15c57983947f7a01250ec864f2d96d5aba3
parent133f14dabed44f7398039e2556bf9b7107f3922e
filter_by works across multiple entities

The :meth:`_sql.Select.filter_by`, :meth:`_sql.Update.filter_by` and
:meth:`_sql.Delete.filter_by` methods now search across all entities
present in the statement, rather than limiting their search to only the
last joined entity or the first FROM entity. This allows these methods
to locate attributes unambiguously across multiple joined tables,
resolving issues where changing the order of operations such as
:meth:`_sql.Select.with_only_columns` would cause the method to fail.

If an attribute name exists in more than one FROM clause entity, an
:class:`_exc.AmbiguousColumnError` is now raised, indicating that
:meth:`_sql.Select.filter` (or :meth:`_sql.Select.where`) should be used
instead with explicit table-qualified column references.

Fixes: #8601
Change-Id: I6a46b8f4784801f95f7980ca8ef92f1947653572
20 files changed:
doc/build/changelog/migration_21.rst
doc/build/changelog/unreleased_21/8601.rst [new file with mode: 0644]
doc/build/tutorial/data_select.rst
lib/sqlalchemy/exc.py
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/writeonly.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/dml.py
lib/sqlalchemy/sql/selectable.py
lib/sqlalchemy/testing/assertions.py
test/base/test_except.py
test/ext/test_hybrid.py
test/orm/dml/test_orm_upd_del_assorted.py
test/orm/test_core_compilation.py
test/orm/test_dynamic.py
test/orm/test_events.py
test/sql/test_delete.py
test/sql/test_select.py
test/sql/test_update.py