]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Resolve SubfieldBase deprecation warnings
authorStephen Finucane <stephen.finucane@intel.com>
Tue, 8 Dec 2015 17:03:10 +0000 (17:03 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Tue, 19 Jan 2016 21:55:28 +0000 (21:55 +0000)
SubfieldBase has been deprecated. It is necessary to add a
'from_db_value' function in place of this mixin.

https://docs.djangoproject.com/en/1.9/releases/1.8/#subfieldbase

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/models.py

index b112a36cd7ae0653d8a119e9fffa60ec3d8d3ca8..a237964a40c7b663aa3a460a508b213de00c3bb8 100644 (file)
@@ -25,6 +25,7 @@ import datetime
 import random
 import re
 
+import django
 from django.contrib.auth.models import User
 from django.conf import settings
 from django.contrib.sites.models import Site
@@ -34,7 +35,6 @@ from django.db.models import Q
 from django.utils.encoding import python_2_unicode_compatible
 from django.utils.functional import cached_property
 from django.utils import six
-from django.utils.six import add_metaclass
 from django.utils.six.moves import filter
 
 from patchwork.parser import extract_tags, hash_patch
@@ -178,8 +178,13 @@ class State(models.Model):
         ordering = ['ordering']
 
 
-@add_metaclass(models.SubfieldBase)
-class HashField(models.CharField):
+if django.VERSION < (1, 8):
+    HashFieldBase = six.with_metaclass(models.SubfieldBase, models.CharField)
+else:
+    HashFieldBase = models.CharField
+
+
+class HashField(HashFieldBase):
 
     def __init__(self, algorithm='sha1', *args, **kwargs):
         self.algorithm = algorithm
@@ -205,6 +210,9 @@ class HashField(models.CharField):
         kwargs['max_length'] = self.n_bytes
         super(HashField, self).__init__(*args, **kwargs)
 
+    def from_db_value(self, value, expression, connection, context):
+        return self.to_python(value)
+
     def db_type(self, connection=None):
         return 'char(%d)' % self.n_bytes