Sometimes it's desirable to use a higher isolation level than the default "read committed" for database operations in Django. The docs warn that:
Under higher isolation levels, your application should be prepared to handle exceptions raised on serialization failures.
But which specific exceptions indicate a serialization failure, versus some other problem with the query or transaction?
A simple retry mechanism after a serialization failure might look like something like this:
for retries in range(0, 3):
try:
with transaction.atomic():
MyModel.objects.update(foo='bar')
except StuffHappened:
continue
else:
break
What specific exceptions should replace StuffHappened
so that only serialization failures, and not other exceptions, result in a retry?
Django has a variety of Database Exceptions and Transaction Exceptions. Might one/some of those represent serialization failures?
I'm specifically interested in postgresql for this.