pub async fn atomic_tree<T, F>(pool: &Pool, f: F) -> Result<T, TreeError>Expand description
Run f inside a framework rustango::sql::atomic scope while
letting it return TreeError — the bridge that lets the
on_commit cache-invalidation pattern reach the tree-write paths.
rustango::sql::atomic fixes its closure’s error to ExecError,
but the tree helpers (cascade_url_path_to_descendants, move_to,
…) speak TreeError, and there’s no TreeError -> ExecError
conversion (only the reverse, via TreeError::Db). This adapter
closes that gap: a TreeError from f is stashed and a sentinel
ExecError is returned to drive atomic’s rollback, then the real
error is recovered afterwards. Recovery keys off the stash, not
the sentinel value, so a genuine ExecError raised by BEGIN /
COMMIT itself is never misread as a domain error.
on_commit callbacks queued by f (e.g. via
crate::cache_invalidate::invalidate_urls_on_commit) fire only on
the commit path — a TreeError rolls the transaction back and drops
them, exactly like a native atomic block.
The cleaner long-term fix is a generic atomic in the framework
(closure returning Result<T, E: From<ExecError>>); until that
lands, this adapter keeps the rollout unblocked.
§Errors
The first TreeError returned by f, or a BEGIN / COMMIT
driver error surfaced as TreeError::Db.