Skip to content

Commit

Permalink
Copy django.db.models.indexes.Index.hash_generator() into PartialInde…
Browse files Browse the repository at this point in the history
…x for compatibility.
  • Loading branch information
mattiaslinnap committed Jul 7, 2019
1 parent 3da3c99 commit 14dccb1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions partial_index/index.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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]

0 comments on commit 14dccb1

Please sign in to comment.