diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-12-09 19:56:42 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-14 23:13:07 +0000 |
commit | 4a784169437c94feb8a0e909515e9cf23236df8c (patch) | |
tree | 9c7fd076b28274a80af53ef7a1b5c3afbef8927d /bitbake/lib/toaster/orm | |
parent | c1c8eff3f91fe2d6cdde92a2b516554eba48a094 (diff) | |
download | poky-4a784169437c94feb8a0e909515e9cf23236df8c.tar.gz |
bitbake: toaster: monkey patch Queryset
Fixed 'database is locked' issue by monkey patching django QuerySet
methods.
The actual patching places were found by bisecting Django codebase.
This commit should be removed after Django is fixed if it's fixed
at all.
(Bitbake rev: 175411bf05423b1892c7928c2b928843b39645f0)
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 'bitbake/lib/toaster/orm')
-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( |