| 1085 | return result |
| 1086 | |
| 1087 | def _take_snapshot(self) -> None: |
| 1088 | if not self._is_transaction_boundary: |
| 1089 | parent = self._parent |
| 1090 | assert parent is not None |
| 1091 | self._new = parent._new |
| 1092 | self._deleted = parent._deleted |
| 1093 | self._dirty = parent._dirty |
| 1094 | self._key_switches = parent._key_switches |
| 1095 | return |
| 1096 | |
| 1097 | is_begin = self.origin in ( |
| 1098 | SessionTransactionOrigin.BEGIN, |
| 1099 | SessionTransactionOrigin.AUTOBEGIN, |
| 1100 | ) |
| 1101 | if not is_begin and not self.session._flushing: |
| 1102 | self.session.flush() |
| 1103 | |
| 1104 | self._new = weakref.WeakKeyDictionary() |
| 1105 | self._deleted = weakref.WeakKeyDictionary() |
| 1106 | self._dirty = weakref.WeakKeyDictionary() |
| 1107 | self._key_switches = weakref.WeakKeyDictionary() |
| 1108 | |
| 1109 | def _restore_snapshot(self, dirty_only: bool = False) -> None: |
| 1110 | """Restore the restoration state taken before a transaction began. |