# database, and are as a result write-only. This value is defined on the
# class level bu may be redefined on a per instance basis.
# Maximum attempts. Each attempt consumes write credits
+ STATUSES_TO_SAVE = frozenset(["running", "done"])
"""Set up preconditions and parameters for the transaction.
# edit and attempt to save it
+ # If we've reached this point, at least the transaction's primary
+ # target exists, and will have been modified/saved even if the rest
+ # of the transaction fails.
+ # So if anything fails beyond this point, we must save the transaction.
+ self.status = "running"
transactors = self._get_transactors()
- self.status = "running"
for getter, setter in transactors:
lambda: self._apply_and_save_target(getter, setter),
- # Always (attempt to) save transaction status
- self._retry(self._assign_datetime_and_save, OverwriteError)
+ if self.status in self.STATUSES_TO_SAVE:
+ # Save the transaction if it succeeded,
+ # or if it failed partway through.
+ self._retry(self._assign_datetime_and_save, OverwriteError)
def save(self, allow_overwrite=True, expected_values=None):
"""If the transaction is transient (``transient = True``),