MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / expire

Method expire

lib/sqlalchemy/orm/session.py:3333–3376  ·  view source on GitHub ↗

Expire the attributes on an instance. Marks the attributes of an instance as out of date. When an expired attribute is next accessed, a query will be issued to the :class:`.Session` object's current transactional context in order to load all expired attributes for th

(
        self, instance: object, attribute_names: Optional[Iterable[str]] = None
    )

Source from the content-addressed store, hash-verified

3331 state._expire(state.dict, self.identity_map._modified)
3332
3333 def expire(
3334 self, instance: object, attribute_names: Optional[Iterable[str]] = None
3335 ) -> None:
3336 """Expire the attributes on an instance.
3337
3338 Marks the attributes of an instance as out of date. When an expired
3339 attribute is next accessed, a query will be issued to the
3340 :class:`.Session` object's current transactional context in order to
3341 load all expired attributes for the given instance. Note that
3342 a highly isolated transaction will return the same values as were
3343 previously read in that same transaction, regardless of changes
3344 in database state outside of that transaction.
3345
3346 To expire all objects in the :class:`.Session` simultaneously,
3347 use :meth:`Session.expire_all`.
3348
3349 The :class:`.Session` object's default behavior is to
3350 expire all state whenever the :meth:`Session.rollback`
3351 or :meth:`Session.commit` methods are called, so that new
3352 state can be loaded for the new transaction. For this reason,
3353 calling :meth:`Session.expire` only makes sense for the specific
3354 case that a non-ORM SQL statement was emitted in the current
3355 transaction.
3356
3357 :param instance: The instance to be refreshed.
3358 :param attribute_names: optional list of string attribute names
3359 indicating a subset of attributes to be expired.
3360
3361 .. seealso::
3362
3363 :ref:`session_expire` - introductory material
3364
3365 :meth:`.Session.expire`
3366
3367 :meth:`.Session.refresh`
3368
3369 :meth:`_orm.Query.populate_existing`
3370
3371 """
3372 try:
3373 state = attributes.instance_state(instance)
3374 except exc.NO_STATE as err:
3375 raise exc.UnmappedInstanceError(instance) from err
3376 self._expire_state(state, attribute_names)
3377
3378 def _expire_state(
3379 self,

Callers 15

test_duplicate_addsMethod · 0.95
test_select_flagsMethod · 0.95
_expireMethod · 0.45
_expire_attributesMethod · 0.45
scoped_session.pyFile · 0.45
test_unexpireMethod · 0.45

Calls 1

_expire_stateMethod · 0.95