Restore the restoration state taken before a transaction began. Corresponds to a rollback.
(self, dirty_only: bool = False)
| 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. |
| 1100 | |
| 1101 | Corresponds to a rollback. |
| 1102 | |
| 1103 | """ |
| 1104 | assert self._is_transaction_boundary |
| 1105 | |
| 1106 | to_expunge = set(self._new).union(self.session._new) |
| 1107 | self.session._expunge_states(to_expunge, to_transient=True) |
| 1108 | |
| 1109 | for s, (oldkey, newkey) in self._key_switches.items(): |
| 1110 | # we probably can do this conditionally based on |
| 1111 | # if we expunged or not, but safe_discard does that anyway |
| 1112 | self.session.identity_map.safe_discard(s) |
| 1113 | |
| 1114 | # restore the old key |
| 1115 | s.key = oldkey |
| 1116 | |
| 1117 | # now restore the object, but only if we didn't expunge |
| 1118 | if s not in to_expunge: |
| 1119 | self.session.identity_map.replace(s) |
| 1120 | |
| 1121 | for s in set(self._deleted).union(self.session._deleted): |
| 1122 | self.session._update_impl(s, revert_deletion=True) |
| 1123 | |
| 1124 | assert not self.session._deleted |
| 1125 | |
| 1126 | for s in self.session.identity_map.all_states(): |
| 1127 | if not dirty_only or s.modified or s in self._dirty: |
| 1128 | s._expire(s.dict, self.session.identity_map._modified) |
| 1129 | |
| 1130 | def _remove_snapshot(self) -> None: |
| 1131 | """Remove the restoration state taken before a transaction began. |
no test coverage detected