From: Mike Bayer Date: Tue, 15 Feb 2022 13:37:44 +0000 (-0500) Subject: add note reiterating do_orm_execute() is for ORM statements only X-Git-Tag: rel_1_4_32~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84ef5f5b061579574360b1044e1d8a9d89059a9b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add note reiterating do_orm_execute() is for ORM statements only Fixes: #7707 Change-Id: I7216f63d9f4269059438e41ad8dd3dffc25a5d03 (cherry picked from commit 619abb52b6f1ee023db0f85fd96ba9f88c8efa7b) --- diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index 9a6acbd422..2bef6394d4 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -1351,7 +1351,7 @@ class SessionEvents(event.Events): """ - _target_class_doc = "SomeSessionOrFactory" + _target_class_doc = "SomeSessionClassOrObject" _dispatch_target = Session @@ -1419,15 +1419,31 @@ class SessionEvents(event.Events): event_key.base_listen(**kw) def do_orm_execute(self, orm_execute_state): - """Intercept statement executions that occur in terms of a :class:`.Session`. - - This event is invoked for all top-level SQL statements invoked - from the :meth:`_orm.Session.execute` method. 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. + """Intercept statement executions that occur on behalf of an + ORM :class:`.Session` object. + + 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. + + .. note:: The :meth:`_orm.SessionEvents.do_orm_execute` event hook + is triggered **for ORM statement executions only**, meaning those + invoked via the :meth:`_orm.Session.execute` and similar methods on + the :class:`_orm.Session` object. It does **not** trigger for + statements that are invoked by SQLAlchemy Core only, i.e. statements + invoked directly using :meth:`_engine.Connection.execute` or + 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 + :meth:`.ConnectionEvents.before_execute` and + :meth:`.ConnectionEvents.before_cursor_execute`. This event is a ``do_`` event, meaning it has the capability to replace the operation that the :meth:`_orm.Session.execute` method normally