From 14dccb1db5d353f186379d860673f7eadf91efc0 Mon Sep 17 00:00:00 2001 From: Mattias Linnap Date: Sun, 7 Jul 2019 23:33:30 +0300 Subject: [PATCH] Copy django.db.models.indexes.Index.hash_generator() into PartialIndex for compatibility. --- partial_index/index.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/partial_index/index.py b/partial_index/index.py index 961045c..bf11f39 100644 --- a/partial_index/index.py +++ b/partial_index/index.py @@ -1,7 +1,10 @@ from django.db.models import Index, Q from django.utils import six +from django.utils.encoding import force_bytes +import hashlib import warnings + from . import query @@ -150,3 +153,14 @@ def set_name_with_model(self, model): 'longer than 3 characters?' ) self.check_name() + + @staticmethod + def _hash_generator(*args): + """Copied from Django 2.1 for compatibility. In Django 2.2 this has been moved into django.db.backends.utils.names_digest(). + + Note that even if Django changes the hash calculation in the future, we should not - that would cause index renames on Django version upgrade. + """ + h = hashlib.md5() + for arg in args: + h.update(force_bytes(arg)) + return h.hexdigest()[:6]