2👍
✅
The code in save_related()
is called inside a transaction. This means that it’s possible for foo()
to run inside a worker process before the transaction in the main process is complete. This will result in the behavior you’ve observed where the task (which is outside of the transaction) will not see the changes to the database.
It’s a race condition and may not always happen. It may be more likely on some machines than others.
One easy fix would be to add a countdown to the task:
tasks.foo.delay(countdown=1)
Source:stackexchange.com