@@ -429,11 +429,26 @@ A :class:`.Session` flush can be forced at any time by calling the
429
429
430
430
session.flush()
431
431
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
437
452
:class: `.sessionmaker ` passing the :paramref: `.Session.autoflush ` parameter as
438
453
``False ``::
439
454
@@ -447,7 +462,8 @@ of using a :class:`.Session` using the
447
462
mysession.add(some_object)
448
463
mysession.flush()
449
464
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
451
467
called, regardless of any "autoflush" settings, when the :class: `.Session ` has
452
468
remaining pending changes to process.
453
469
0 commit comments