python3: encode unicode-objects before hashing (#40911)
This commit is contained in:
parent
921a3f27e1
commit
dcb5351962
|
@ -18,7 +18,7 @@ from hashlib import md5
|
|||
|
||||
from django.apps import apps
|
||||
from django.db import models, connection
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
||||
|
@ -74,7 +74,7 @@ class CommonSchema(models.Model):
|
|||
|
||||
def rebuild_string_index(self, cursor, table, path):
|
||||
expr = 'immutable_normalize((content%s))' % self.path_to_sql_expr(path)
|
||||
key = md5(expr.encode('utf-8')).hexdigest()[:8]
|
||||
key = md5(force_bytes(expr)).hexdigest()[:8]
|
||||
sql = ('CREATE INDEX zoo_entity_%s_gin_%s_dynamic_idx ON %s USING gin ((%s) '
|
||||
' gin_trgm_ops) WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
cursor.execute(sql)
|
||||
|
@ -84,7 +84,7 @@ class CommonSchema(models.Model):
|
|||
|
||||
def rebuild_string_date_time_index(self, cursor, table, path):
|
||||
expr = 'immutable_date(content%s)' % self.path_to_sql_expr(path)
|
||||
key = md5(expr).hexdigest()[:8]
|
||||
key = md5(force_bytes(expr)).hexdigest()[:8]
|
||||
sql = ('CREATE INDEX zoo_entity_%s_%s_dynamic_idx ON %s (%s) '
|
||||
'WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
cursor.execute(sql)
|
||||
|
@ -99,7 +99,7 @@ class CommonSchema(models.Model):
|
|||
else:
|
||||
raise NotImplementedError(self)
|
||||
|
||||
key = md5(expr).hexdigest()[:8]
|
||||
key = md5(force_bytes(expr)).hexdigest()[:8]
|
||||
gin_sql = ('CREATE INDEX zoo_entity_%s_gin_%s_dynamic_idx ON %s USING gin ((%s) '
|
||||
'gin_trgm_ops) WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
gist_sql = ('CREATE INDEX zoo_entity_%s_gist_%s_dynamic_idx ON %s USING gist ((%s)'
|
||||
|
|
Loading…
Reference in New Issue