use std::future::Future;
tokio::task_local! {
static IN_MUTATION_CALLBACK: ();
}
pub async fn run<F: Future>(callback: F) -> F::Output {
IN_MUTATION_CALLBACK.scope((), callback).await
}
pub fn ensure_allowed() -> Result<(), crate::Error> {
if IN_MUTATION_CALLBACK.try_with(|()| ()).is_ok() {
return Err(crate::Error::Validation(
"reentrant ORM access from a mutation policy or lifecycle callback is unsupported while its transaction is borrowed; perform database authorization before the mutation and defer only post-commit effects to after_commit".to_string(),
));
}
Ok(())
}