| 1074 | return result |
| 1075 | |
| 1076 | def _take_snapshot(self) -> None: |
| 1077 | if not self._is_transaction_boundary: |
| 1078 | parent = self._parent |
| 1079 | assert parent is not None |
| 1080 | self._new = parent._new |
| 1081 | self._deleted = parent._deleted |
| 1082 | self._dirty = parent._dirty |
| 1083 | self._key_switches = parent._key_switches |
| 1084 | return |
| 1085 | |
| 1086 | is_begin = self.origin in ( |
| 1087 | SessionTransactionOrigin.BEGIN, |
| 1088 | SessionTransactionOrigin.AUTOBEGIN, |
| 1089 | ) |
| 1090 | if not is_begin and not self.session._flushing: |
| 1091 | self.session.flush() |
| 1092 | |
| 1093 | self._new = weakref.WeakKeyDictionary() |
| 1094 | self._deleted = weakref.WeakKeyDictionary() |
| 1095 | self._dirty = weakref.WeakKeyDictionary() |
| 1096 | self._key_switches = weakref.WeakKeyDictionary() |
| 1097 | |
| 1098 | def _restore_snapshot(self, dirty_only: bool = False) -> None: |
| 1099 | """Restore the restoration state taken before a transaction began. |