diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-12-09 19:56:40 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-14 23:12:44 +0000 |
commit | eb305308ca8f6228c6f52dac1bd941f29c7e5eb6 (patch) | |
tree | 1cda3567e178a1d483a1aa1f241132aeb626d2e0 /lib/toaster/orm | |
parent | d5ca2bae623db214764324da5c9e4dac6beef760 (diff) | |
download | bitbake-eb305308ca8f6228c6f52dac1bd941f29c7e5eb6.tar.gz |
toaster: work around 'database is locked' error
When sqlite can not cope with a stream of 'insert' queries it throws
'database is locked' exception.
Wrapping model.save in transaction.atomic context and repeating the call
should solve this issue.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster/orm')
-rw-r--r-- | lib/toaster/orm/models.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py index 3c51c6f79..0d598aca1 100644 --- a/lib/toaster/orm/models.py +++ b/lib/toaster/orm/models.py @@ -29,10 +29,28 @@ from django.core import validators from django.conf import settings import django.db.models.signals - import logging logger = logging.getLogger("toaster") +if 'sqlite' in settings.DATABASES['default']['ENGINE']: + from django.db import transaction, OperationalError + from time import sleep + + _base_save = models.Model.save + def save(self, *args, **kwargs): + while True: + try: + with transaction.atomic(): + return _base_save(self, *args, **kwargs) + except OperationalError as err: + if 'database is locked' in str(err): + logger.warning("%s, model: %s, args: %s, kwargs: %s", + err, self.__class__, args, kwargs) + sleep(0.5) + continue + raise + + models.Model.save = save class GitURLValidator(validators.URLValidator): import re |