django transaction rollback on deadlock detection

40 views
Skip to first unread message

William Messer

unread,
Jun 23, 2016, 6:30:04 AM6/23/16
to Django users
As far as I can see, there's nothing in the django database doco about transaction failure due to deadlock detection in a multi-user environment. Does this mean that django retries transactions itself a number of times e.g., as google appengine does? I'm pretty sure this would have been mentioned if such were the case.
Alternatively, it's up to the programmer to handle deadlocks in code, e.g., by the following method that handles OperationalError exception:
        except OperationalError as e:
            code = e.args[0]
            if attempts == 2 or code != 1213:
                raise e
            attempts += 1
            time.sleep(0.2)
The above assumes the transaction is executed in a loop for retries to occur.

Is this the way to do it?





Reply all
Reply to author
Forward
0 new messages