def METHOD_NAME(
    cls, write_target_db: DatabaseAPI
) -> Iterator[AtomicWriteBatchAPI]:
    """
    Commit all writes inside the context, unless an exception was raised.
    Although this is technically an external API, it (and this whole class) is only
    intended to be used by AtomicDB.
    """
    readable_write_batch: AtomicDBWriteBatch = cls(write_target_db)
    try:
        yield readable_write_batch
    except Exception:
        cls.logger.exception(
            "Unexpected error in atomic db write, dropped partial writes: %r",
            readable_write_batch._diff(),
        )
        raise
    else:
        readable_write_batch._commit()
    finally:
        # force a shutdown of this batch, to prevent out-of-context usage
        readable_write_batch._track_diff = None
        readable_write_batch._write_target_db = None