]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Improve orm event docs
authorFederico Caselli <cfederico87@gmail.com>
Fri, 24 Feb 2023 22:24:03 +0000 (23:24 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 27 Feb 2023 22:08:02 +0000 (23:08 +0100)
Change-Id: Ia4f8ce497565c9d5e8df4ef7cc3c3e645f995ff3

lib/sqlalchemy/orm/events.py
lib/sqlalchemy/orm/session.py

index bf3da5015f5bee95c7ed0ba26b71f20a8e3488c0..413bfbfcbea080e8fb7829ef4fa13d787f40759b 100644 (file)
@@ -1683,11 +1683,13 @@ class SessionEvents(event.Events[Session]):
         This event is invoked for all top-level SQL statements invoked from the
         :meth:`_orm.Session.execute` method, as well as related methods such as
         :meth:`_orm.Session.scalars` and :meth:`_orm.Session.scalar`. As of
-        SQLAlchemy 1.4, all ORM queries emitted on behalf of a
-        :class:`_orm.Session` will flow through this method, so this event hook
-        provides the single point at which ORM queries of all types may be
-        intercepted before they are invoked, and additionally to replace their
-        execution with a different process.
+        SQLAlchemy 1.4, all ORM queries that run through the
+        :meth:`_orm.Session.execute` method as well as related methods
+        :meth:`_orm.Session.scalars`, :meth:`_orm.Session.scalar` etc.
+        will participate in this event.
+        This event hook does **not** apply to the queries that are
+        emitted internally within the ORM flush process, i.e. the
+        process described at :ref:`session_flushing`.
 
         .. note::  The :meth:`_orm.SessionEvents.do_orm_execute` event hook
            is triggered **for ORM statement executions only**, meaning those
@@ -1698,11 +1700,17 @@ class SessionEvents(event.Events[Session]):
            otherwise originating from an :class:`_engine.Engine` object without
            any :class:`_orm.Session` involved. To intercept **all** SQL
            executions regardless of whether the Core or ORM APIs are in use,
-           see the event hooks at
-           :class:`.ConnectionEvents`, such as
+           see the event hooks at :class:`.ConnectionEvents`, such as
            :meth:`.ConnectionEvents.before_execute` and
            :meth:`.ConnectionEvents.before_cursor_execute`.
 
+           Also, this event hook does **not** apply to queries that are
+           emitted internally within the ORM flush process,
+           i.e. the process described at :ref:`session_flushing`; to
+           intercept steps within the flush process, see the event
+           hooks described at :ref:`session_persistence_events` as
+           well as :ref:`session_persistence_mapper`.
+
         This event is a ``do_`` event, meaning it has the capability to replace
         the operation that the :meth:`_orm.Session.execute` method normally
         performs.  The intended use for this includes sharding and
index 1a6b050dccbfd5f30d90a799ab07a1a8f92503f7..f2a46b0d075bbc54cf902bb596e73d5dd19bc0b5 100644 (file)
@@ -546,8 +546,8 @@ class ORMExecuteState(util.MemoizedSlots):
     def is_orm_statement(self) -> bool:
         """return True if the operation is an ORM statement.
 
-        This indicates that the select(), update(), or delete() being
-        invoked contains ORM entities as subjects.   For a statement
+        This indicates that the select(), insert(), update(), or delete()
+        being invoked contains ORM entities as subjects.   For a statement
         that does not have ORM entities and instead refers only to
         :class:`.Table` metadata, it is invoked as a Core SQL statement
         and no ORM-level automation takes place.