Skip to content

Commit 4acf50c

Browse files
committed
i forgot about begin_nested()
make bulleted lists of what is autoflush and what's not. Change-Id: Id3bc4714013e9df243d804d7b5b60c6ef75e1316
1 parent ed2b29d commit 4acf50c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

doc/build/orm/session_basics.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,26 @@ A :class:`.Session` flush can be forced at any time by calling the
429429

430430
session.flush()
431431

432-
The flush which occurs automatically within the scope of
433-
:meth:`_orm.Session.execute`, :class:`_query.Query`, as well as other
434-
:class:`.Session` methods such as :meth:`.Session.merge` (but **not** including
435-
the :meth:`.Session.commit` method) is known as **autoflush**. This "autoflush"
436-
behavior can be disabled by constructing a :class:`.Session` or
432+
The flush which occurs automatically within the scope of certain methods
433+
is known as **autoflush**. Autoflush is defined as a configurable,
434+
automatic flush call which occurs at the beginning of methods including:
435+
436+
* :meth:`_orm.Session.execute` and other SQL-executing methods
437+
* When a :class:`_query.Query` is invoked to send SQL to the database
438+
* Within the :meth:`.Session.merge` method before querying the database
439+
* When objects are :ref:`refreshed <session_expiring>`
440+
* When ORM :term:`lazy load` operations occur against unloaded object
441+
attributes.
442+
443+
There are also points at which flushes occur **unconditionally**; these
444+
points are within key transactional boundaries which include:
445+
446+
* Within the process of the :meth:`.Session.commit` method
447+
* When :meth:`.Session.begin_nested` is called
448+
* When the :meth:`.Session.prepare` 2PC method is used.
449+
450+
The **autoflush** behavior, as applied to the previous list of items,
451+
can be disabled by constructing a :class:`.Session` or
437452
:class:`.sessionmaker` passing the :paramref:`.Session.autoflush` parameter as
438453
``False``::
439454

@@ -447,7 +462,8 @@ of using a :class:`.Session` using the
447462
mysession.add(some_object)
448463
mysession.flush()
449464

450-
The flush process **always occurs** when the :meth:`.Session.commit` method is
465+
**To reiterate:** The flush process **always occurs** when transactional
466+
methods such as :meth:`.Session.commit` and :meth:`.Session.begin_nested` are
451467
called, regardless of any "autoflush" settings, when the :class:`.Session` has
452468
remaining pending changes to process.
453469

0 commit comments

Comments
 (0)