Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Classe « SessionEvents »

Méthode sqlalchemy.orm.SessionEvents.loaded_as_persistent

Signature de la méthode loaded_as_persistent

def loaded_as_persistent(self, session, instance) 

Description

loaded_as_persistent.__doc__

Intercept the "loaded as persistent" transition for a specific object.

.. container:: event_signatures

     Example argument forms::

        from sqlalchemy import event


        @event.listens_for(SomeSessionOrFactory, 'loaded_as_persistent')
        def receive_loaded_as_persistent(session, instance):
            "listen for the 'loaded_as_persistent' event"

            # ... (event handling logic) ...


This event is invoked within the ORM loading process, and is invoked
very similarly to the :meth:`.InstanceEvents.load` event.  However,
the event here is linkable to a :class:`.Session` class or instance,
rather than to a mapper or class hierarchy, and integrates
with the other session lifecycle events smoothly.  The object
is guaranteed to be present in the session's identity map when
this event is called.

.. note:: This event is invoked within the loader process before
   eager loaders may have been completed, and the object's state may
   not be complete.  Additionally, invoking row-level refresh
   operations on the object will place the object into a new loader
   context, interfering with the existing load context.   See the note
   on :meth:`.InstanceEvents.load` for background on making use of the
   :paramref:`.SessionEvents.restore_load_context` parameter, which
   works in the same manner as that of
   :paramref:`.InstanceEvents.restore_load_context`, in  order to
   resolve this scenario.

:param session: target :class:`.Session`

:param instance: the ORM-mapped instance being operated upon.

.. versionadded:: 1.1

.. seealso::

    :ref:`session_lifecycle_events`