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
)
| 3229 | state._expire(state.dict, self.identity_map._modified) |
| 3230 | |
| 3231 | def expire( |
| 3232 | self, instance: object, attribute_names: Optional[Iterable[str]] = None |
| 3233 | ) -> None: |
| 3234 | """Expire the attributes on an instance. |
| 3235 | |
| 3236 | Marks the attributes of an instance as out of date. When an expired |
| 3237 | attribute is next accessed, a query will be issued to the |
| 3238 | :class:`.Session` object's current transactional context in order to |
| 3239 | load all expired attributes for the given instance. Note that |
| 3240 | a highly isolated transaction will return the same values as were |
| 3241 | previously read in that same transaction, regardless of changes |
| 3242 | in database state outside of that transaction. |
| 3243 | |
| 3244 | To expire all objects in the :class:`.Session` simultaneously, |
| 3245 | use :meth:`Session.expire_all`. |
| 3246 | |
| 3247 | The :class:`.Session` object's default behavior is to |
| 3248 | expire all state whenever the :meth:`Session.rollback` |
| 3249 | or :meth:`Session.commit` methods are called, so that new |
| 3250 | state can be loaded for the new transaction. For this reason, |
| 3251 | calling :meth:`Session.expire` only makes sense for the specific |
| 3252 | case that a non-ORM SQL statement was emitted in the current |
| 3253 | transaction. |
| 3254 | |
| 3255 | :param instance: The instance to be refreshed. |
| 3256 | :param attribute_names: optional list of string attribute names |
| 3257 | indicating a subset of attributes to be expired. |
| 3258 | |
| 3259 | .. seealso:: |
| 3260 | |
| 3261 | :ref:`session_expire` - introductory material |
| 3262 | |
| 3263 | :meth:`.Session.expire` |
| 3264 | |
| 3265 | :meth:`.Session.refresh` |
| 3266 | |
| 3267 | :meth:`_orm.Query.populate_existing` |
| 3268 | |
| 3269 | """ |
| 3270 | try: |
| 3271 | state = attributes.instance_state(instance) |
| 3272 | except exc.NO_STATE as err: |
| 3273 | raise exc.UnmappedInstanceError(instance) from err |
| 3274 | self._expire_state(state, attribute_names) |
| 3275 | |
| 3276 | def _expire_state( |
| 3277 | self, |