diff options
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 3c51c6f798..0d598aca19 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -29,10 +29,28 @@ from django.core import validators | |||
29 | from django.conf import settings | 29 | from django.conf import settings |
30 | import django.db.models.signals | 30 | import django.db.models.signals |
31 | 31 | ||
32 | |||
33 | import logging | 32 | import logging |
34 | logger = logging.getLogger("toaster") | 33 | logger = logging.getLogger("toaster") |
35 | 34 | ||
35 | if 'sqlite' in settings.DATABASES['default']['ENGINE']: | ||
36 | from django.db import transaction, OperationalError | ||
37 | from time import sleep | ||
38 | |||
39 | _base_save = models.Model.save | ||
40 | def save(self, *args, **kwargs): | ||
41 | while True: | ||
42 | try: | ||
43 | with transaction.atomic(): | ||
44 | return _base_save(self, *args, **kwargs) | ||
45 | except OperationalError as err: | ||
46 | if 'database is locked' in str(err): | ||
47 | logger.warning("%s, model: %s, args: %s, kwargs: %s", | ||
48 | err, self.__class__, args, kwargs) | ||
49 | sleep(0.5) | ||
50 | continue | ||
51 | raise | ||
52 | |||
53 | models.Model.save = save | ||
36 | 54 | ||
37 | class GitURLValidator(validators.URLValidator): | 55 | class GitURLValidator(validators.URLValidator): |
38 | import re | 56 | import re |