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 :

Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé
Classe « scoped_session »

Méthode sqlalchemy.orm.scoped_session.refresh

Signature de la méthode refresh

def refresh(self, instance: 'object', attribute_names: 'Optional[Iterable[str]]' = None, with_for_update: 'ForUpdateParameter' = None) -> 'None' 

Description

help(scoped_session.refresh)

Expire and refresh attributes on the given instance.

.. container:: class_bases

    Proxied for the :class:`_orm.Session` class on
    behalf of the :class:`_orm.scoping.scoped_session` class.

The selected attributes will first be expired as they would when using
:meth:`_orm.Session.expire`; then a SELECT statement will be issued to
the database to refresh column-oriented attributes with the current
value available in the current transaction.

:func:`_orm.relationship` oriented attributes will also be immediately
loaded if they were already eagerly loaded on the object, using the
same eager loading strategy that they were loaded with originally.

.. versionadded:: 1.4 - the :meth:`_orm.Session.refresh` method
   can also refresh eagerly loaded attributes.

:func:`_orm.relationship` oriented attributes that would normally
load using the ``select`` (or "lazy") loader strategy will also
load **if they are named explicitly in the attribute_names
collection**, emitting a SELECT statement for the attribute using the
``immediate`` loader strategy.  If lazy-loaded relationships are not
named in :paramref:`_orm.Session.refresh.attribute_names`, then
they remain as "lazy loaded" attributes and are not implicitly
refreshed.

.. versionchanged:: 2.0.4  The :meth:`_orm.Session.refresh` method
   will now refresh lazy-loaded :func:`_orm.relationship` oriented
   attributes for those which are named explicitly in the
   :paramref:`_orm.Session.refresh.attribute_names` collection.

.. tip::

    While the :meth:`_orm.Session.refresh` method is capable of
    refreshing both column and relationship oriented attributes, its
    primary focus is on refreshing of local column-oriented attributes
    on a single instance. For more open ended "refresh" functionality,
    including the ability to refresh the attributes on many objects at
    once while having explicit control over relationship loader
    strategies, use the
    :ref:`populate existing <orm_queryguide_populate_existing>` feature
    instead.

Note that a highly isolated transaction will return the same values as
were previously read in that same transaction, regardless of changes
in database state outside of that transaction.   Refreshing
attributes usually only makes sense at the start of a transaction
where database rows have not yet been accessed.

:param attribute_names: optional.  An iterable collection of
  string attribute names indicating a subset of attributes to
  be refreshed.

:param with_for_update: optional boolean ``True`` indicating FOR UPDATE
  should be used, or may be a dictionary containing flags to
  indicate a more specific set of FOR UPDATE flags for the SELECT;
  flags should match the parameters of
  :meth:`_query.Query.with_for_update`.
  Supersedes the :paramref:`.Session.refresh.lockmode` parameter.

.. seealso::

    :ref:`session_expire` - introductory material

    :meth:`.Session.expire`

    :meth:`.Session.expire_all`

    :ref:`orm_queryguide_populate_existing` - allows any ORM query
    to refresh objects as they would be loaded normally.




Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé