MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _expire

Method _expire

lib/sqlalchemy/orm/state.py:731–779  ·  view source on GitHub ↗
(
        self, dict_: _InstanceDict, modified_set: Set[InstanceState[Any]]
    )

Source from the content-addressed store, hash-verified

729 return _set_callable
730
731 def _expire(
732 self, dict_: _InstanceDict, modified_set: Set[InstanceState[Any]]
733 ) -> None:
734 self.expired = True
735 if self.modified:
736 modified_set.discard(self)
737 self.committed_state.clear()
738 self.modified = False
739
740 self._strong_obj = None
741
742 if "_pending_mutations" in self.__dict__:
743 del self.__dict__["_pending_mutations"]
744
745 if "parents" in self.__dict__:
746 del self.__dict__["parents"]
747
748 self.expired_attributes.update(
749 [impl.key for impl in self.manager._loader_impls]
750 )
751
752 if self.callables:
753 # the per state loader callables we can remove here are
754 # LoadDeferredColumns, which undefers a column at the instance
755 # level that is mapped with deferred, and LoadLazyAttribute,
756 # which lazy loads a relationship at the instance level that
757 # is mapped with "noload" or perhaps "immediateload".
758 # Before 1.4, only column-based
759 # attributes could be considered to be "expired", so here they
760 # were the only ones "unexpired", which means to make them deferred
761 # again. For the moment, as of 1.4 we also apply the same
762 # treatment relationships now, that is, an instance level lazy
763 # loader is reset in the same way as a column loader.
764 for k in self.expired_attributes.intersection(self.callables):
765 del self.callables[k]
766
767 for k in self.manager._collection_impl_keys.intersection(dict_):
768 collection = dict_.pop(k)
769 collection._sa_adapter.invalidated = True
770
771 if self._last_known_values:
772 self._last_known_values.update(
773 {k: dict_[k] for k in self._last_known_values if k in dict_}
774 )
775
776 for key in self.manager._all_key_set.intersection(dict_):
777 del dict_[key]
778
779 self.manager.dispatch.expire(self, None)
780
781 def _expire_attributes(
782 self,

Callers 10

_restore_snapshotMethod · 0.80
_remove_snapshotMethod · 0.80
expire_allMethod · 0.80
_conditional_expireMethod · 0.80
test_deferredMethod · 0.80
test_deferredMethod · 0.80
test_expiredMethod · 0.80

Calls 6

discardMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45
intersectionMethod · 0.45
popMethod · 0.45
expireMethod · 0.45

Tested by 5

test_deferredMethod · 0.64
test_deferredMethod · 0.64
test_expiredMethod · 0.64