MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _expire

Method _expire

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

Source from the content-addressed store, hash-verified

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