to pass objects off to other systems that can't run in the same context
even though they're in the same process. In this case, the application
should try to make appropriate use of :term:`eager loading` to ensure
- that objects have what they need up front. As an additional measure,
- special directives like the :func:`.raiseload` option can ensure that
- systems don't call upon lazy loading when its not expected.
+ that objects have what they need up front.
+
+ When using this approach, it is usually necessary that the
+ :paramref:`_orm.Session.expire_on_commit` parameter be set to ``False``, so
+ that after a :meth:`_orm.Session.commit` operation, the objects within the
+ session aren't :term:`expired`, which would incur a lazy load if their
+ attributes were subsequently accessed. Additionally, the
+ :meth:`_orm.Session.rollback` method unconditionally expires all contents in
+ the :class:`_orm.Session` and should also be avoided in non-error scenarios.
.. seealso::
:ref:`loading_toplevel` - detailed documentation on eager loading and other
relationship-oriented loading techniques
+ :ref:`session_committing` - background on session commit
+
+ :ref:`session_expire` - background on attribute expiry
+
.. _error_7s2a:
so that all attribute/object access subsequent to a completed
transaction will load from the most recent database state.
+ .. seealso::
+
+ :ref:`session_committing`
+
+
:param future: if True, use 2.0 style behavior for the
:meth:`_orm.Session.execute` method. Future mode includes the
following behaviors:
:class:`.Session` objects.
:param autocommit: The autocommit setting to use with newly created
:class:`.Session` objects.
- :param expire_on_commit=True: the expire_on_commit setting to use
+ :param expire_on_commit=True: the
+ :paramref:`_orm.Session.expire_on_commit` setting to use
with newly created :class:`.Session` objects.
+
:param info: optional dictionary of information that will be available
via :attr:`.Session.info`. Note this dictionary is *updated*, not
replaced, when the ``info`` parameter is specified to the specific