transaction.atomic good practices13 Oct 2020
transaction.atomic() we should remember that it can commit or rollback just the db related calls inside the
atomic() block. It’s not able to rewind a HTTP call, a call to redis or putting a payload on any queueing system. This means in case of a rollback we’d emit an event or call an external API to inform it about an object which effectively was not saved to the database.
In the project I’m working on now a real life scenario would e.g. end up sending an e-mail or an SMS to a person when their order was not created and customer support would need to deal with this.
A good practice is tho have the
atomic() block the minimal set of db calls which have to be run together. Everything else should ideally be moved out.