transaction.atomic good practices
When using 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.
π Celery and transaction.atomic Stack Overflow thread