Handle locked database: django.db.utils.OperationalError
When using an sqlite
database, background tasks might lock the database for all write operations for quite some time. If the user tries any other write operation during that period, a django.db.utils.OperationalError
will be raised.
We should investigate whether it is possible to not lock the entire database while a background task is running. That might not be possible though due to the nature of sqlite
.
Since the same problem can also occur if two threads try to write to the same row in MySQL, we should in any case catch this exception and show a meaningful error message to the user. Maybe there can be a progress bar and notification from the server to the client when the database gets unlocked, so the user's action will automatically be completed as soon as the database is available for write operations again.