#Will an error in a post_save signal rollback a model save() in an atomic block?

5 messages · Page 1 of 1 (latest)

high silo
#

I'm working with Django and have a question regarding transaction behavior when using signals.

Let's say I have a Django model where the save() method is wrapped inside an @transaction.atomic block. I also have a post_save signal connected to this model, and that signal is also wrapped in @transaction.atomic.

If an exception is raised inside the post_save signal, will that error cause the changes made in the save() method to be rolled back as well?

In other words:

  • Does the post_save signal share the same database transaction as the save() method when using transaction.atomic?
  • If so, will any unhandled exception in the signal handler cause the entire transaction—including the model save—to be rolled back?
slow lava
#

Try to not ask the same question in multiple places.

high silo