]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
add columns_clause_froms and related use cases
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 23 Jul 2021 20:07:50 +0000 (16:07 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 7 Aug 2021 18:47:29 +0000 (14:47 -0400)
commitd49eef15bfb759fb33d7d23988cc5a385d9e8a40
tree8dc301d21600f147aa1647ef1c74e718b8484925
parent8822d832679cdc13bb631dd221d0f5932f6540c7
add columns_clause_froms and related use cases

Added new attribute :attr:`_sql.Select.columns_clause_froms` that will
retrieve the FROM list implied by the columns clause of the
:class:`_sql.Select` statement. This differs from the old
:attr:`_sql.Select.froms` collection in that it does not perform any ORM
compilation steps, which necessarily deannotate the FROM elements and do
things like compute joinedloads etc., which makes it not an appropriate
candidate for the :meth:`_sql.Select.select_from` method. Additionally adds
a new parameter
:paramref:`_sql.Select.with_only_columns.maintain_column_froms` that
transfers this collection to :meth:`_sql.Select.select_from` before
replacing the columns collection.

In addition, the :attr:`_sql.Select.froms` is renamed to
:meth:`_sql.Select.get_final_froms`, to stress that this collection is not
a simple accessor and is instead calculated given the full state of the
object, which can be an expensive call when used in an ORM context.

Additionally fixes a regression involving the
:func:`_orm.with_only_columns` function to support applying criteria to
column elements that were replaced with either
:meth:`_sql.Select.with_only_columns` or :meth:`_orm.Query.with_entities` ,
which had broken as part of :ticket:`6503` released in 1.4.19.

Fixes: #6808
Change-Id: Ib5d66cce488bbaca06dab4f68fb5cdaa73e8823e
doc/build/changelog/unreleased_14/6808.rst [new file with mode: 0644]
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/sql/selectable.py
test/orm/test_core_compilation.py
test/orm/test_relationship_criteria.py
test/sql/test_deprecations.py
test/sql/test_selectable.py