]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
use an ORM compile state for all statements with any ORM entities anywhere
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 May 2023 13:35:30 +0000 (09:35 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 May 2023 14:33:08 +0000 (10:33 -0400)
commita2e27eb4d718f732494ff008aad1d0cd56c4ad88
tree339b359e93828fd30f65ce0621929c316327889b
parent9764a07c53a7627b7953e6df39428f7ce5af7600
use an ORM compile state for all statements with any ORM entities anywhere

As more projects are using new-style "2.0" ORM querying, it's becoming
apparent that the conditional nature of "autoflush", being based on whether
or not the given statement refers to ORM entities, is becoming more of a
key behavior. Up until now, the "ORM" flag for a statement has been loosely
based around whether or not the statement returns rows that correspond to
ORM entities or columns; the original purpose of the "ORM" flag was to
enable ORM-entity fetching rules which apply post-processing to Core result
sets as well as ORM loader strategies to the statement.  For statements
that don't build on rows that contain ORM entities, the "ORM" flag was
considered to be mostly unnecessary.

It still may be the case that "autoflush" would be better taking effect for
*all* usage of :meth:`_orm.Session.execute` and related methods, even for
purely Core SQL constructs. However, this still could impact legacy cases
where this is not expected and may be more of a 2.1 thing. For now however,
the rules for the "ORM-flag" have been opened up so that a statement that
includes ORM entities or attributes anywhere within, including in the WHERE
/ ORDER BY / GROUP BY clause alone, within scalar subqueries, etc. will
enable this flag.  This will cause "autoflush" to occur for such statements
and also be visible via the :attr:`_orm.ORMExecuteState.is_orm_statement`
event-level attribute.

Fixes: #9805
Change-Id: Idcabefc8fedd14edcf603b90e26e5982c849a1fc
doc/build/changelog/unreleased_20/9805.rst [new file with mode: 0644]
lib/sqlalchemy/orm/bulk_persistence.py
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/sql/coercions.py
lib/sqlalchemy/sql/dml.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/selectable.py
test/orm/test_bind.py
test/orm/test_core_compilation.py
test/orm/test_events.py