| 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, |