toaster: Update to support Django-3
PATCH 1/1 toaster: Update to support Django-3
Update the Toaster code to support both Django-2 and Django-3.
- The module 'six' was for Python 2/3 compatibility. That package is both no longer needed and is deprecated on recent hosts, so explicitly replace 'reraise' with the Python-3 version.
- The 'autocommits_when_autocommit_is_off' attribute is deprecated in Django-3. It was used for 'sqlite3 in Python < 3.6 which doesn't handle transactions and savepoints properly when autocommit is off'
- Toaster requirements file updated to include Django 3.0*.
[YOCTO #13888]
Signed-off-by David Reyna <[email protected]>
--- bitbake/lib/bb/ui/buildinfohelper.py | 6 ++++-- bitbake/lib/toaster/orm/models.py | 15 +++++++++++++-- bitbake/toaster-requirements.txt | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-)
bitbake/lib/bb/ui/buildinfohelper.py +4 -2
@@ -894,8 +894,10 @@ class BuildInfoHelper(object): self.autocommit_step = 1 self.server = server # we use manual transactions if the database doesn't autocommit on us - if not connection.features.autocommits_when_autocommit_is_off: - transaction.set_autocommit(False) + # deprecated with Django 3 + if 2 == django.VERSION[0]: + if not connection.features.autocommits_when_autocommit_is_off: + transaction.set_autocommit(False) self.orm_wrapper = ORMWrapper() self.has_build_history = has_build_history self.tmp_dir = self.server.runCommand(["getVariable", "TMPDIR"])[0]
bitbake/lib/toaster/orm/models.py +13 -2
@@ -58,7 +58,18 @@ if 'sqlite' in settings.DATABASES['default']['ENGINE']: return _base_insert(self, *args, **kwargs) QuerySet._insert = _insert - from django.utils import six + #from django.utils import six (deprecate with Python-3/latest 'six') + def six_reraise(tp, value, tb=None): + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None + def _create_object_from_params(self, lookup, params): """ Tries to create an object using passed params.
@@ -73,7 +84,7 @@ if 'sqlite' in settings.DATABASES['default']['ENGINE']: return self.get(**lookup), False except self.model.DoesNotExist: pass - six.reraise(*exc_info) + six_reraise(*exc_info) QuerySet._create_object_from_params = _create_object_from_params
bitbake/toaster-requirements.txt +1 -1
@@ -1,3 +1,3 @@ -Django>2.2,<2.3 +Django>2.2,<3.1 beautifulsoup4>=4.4.0 pytz
Signature · 1 line
2.20.1