[PATCH] toaster: Update to support Django-3

"Reyna, David" <[email protected]>
Newsgroups org.yoctoproject.lists.toaster
Message-ID <[email protected]>
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(-)

diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index 82c62e3324..b20774d895 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -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]
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 7f7e922ade..abd657b9e3 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -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
 
diff --git a/bitbake/toaster-requirements.txt b/bitbake/toaster-requirements.txt
index 735b614546..56a51fc667 100644
--- a/bitbake/toaster-requirements.txt
+++ b/bitbake/toaster-requirements.txt
@@ -1,3 +1,3 @@
-Django>2.2,<2.3
+Django>2.2,<3.1
 beautifulsoup4>=4.4.0
 pytz
-- 
2.20.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.