diff options
| -rw-r--r-- | bitbake/lib/toaster/orm/models.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 0d598aca19..6e87c54476 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
| @@ -52,6 +52,36 @@ if 'sqlite' in settings.DATABASES['default']['ENGINE']: | |||
| 52 | 52 | ||
| 53 | models.Model.save = save | 53 | models.Model.save = save |
| 54 | 54 | ||
| 55 | # HACK: Monkey patch Django to fix 'database is locked' issue | ||
| 56 | |||
| 57 | from django.db.models.query import QuerySet | ||
| 58 | _base_insert = QuerySet._insert | ||
| 59 | def _insert(self, *args, **kwargs): | ||
| 60 | with transaction.atomic(using=self.db, savepoint=False): | ||
| 61 | return _base_insert(self, *args, **kwargs) | ||
| 62 | QuerySet._insert = _insert | ||
| 63 | |||
| 64 | from django.utils import six | ||
| 65 | def _create_object_from_params(self, lookup, params): | ||
| 66 | """ | ||
| 67 | Tries to create an object using passed params. | ||
| 68 | Used by get_or_create and update_or_create | ||
| 69 | """ | ||
| 70 | try: | ||
| 71 | obj = self.create(**params) | ||
| 72 | return obj, True | ||
| 73 | except IntegrityError: | ||
| 74 | exc_info = sys.exc_info() | ||
| 75 | try: | ||
| 76 | return self.get(**lookup), False | ||
| 77 | except self.model.DoesNotExist: | ||
| 78 | pass | ||
| 79 | six.reraise(*exc_info) | ||
| 80 | |||
| 81 | QuerySet._create_object_from_params = _create_object_from_params | ||
| 82 | |||
| 83 | # end of HACK | ||
| 84 | |||
| 55 | class GitURLValidator(validators.URLValidator): | 85 | class GitURLValidator(validators.URLValidator): |
| 56 | import re | 86 | import re |
| 57 | regex = re.compile( | 87 | regex = re.compile( |
