Skip to content

Commit 267693c

Browse files
committed
feat(models): Support unicode strings in python2
1 parent c5ce9ca commit 267693c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

algoliasearch_django/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from itertools import chain
66
import logging
77

8+
import sys
89
from algoliasearch.helpers import AlgoliaException
910
from django.db.models.query_utils import DeferredAttribute
1011

@@ -93,15 +94,17 @@ def __init__(self, model, client, settings):
9394

9495
# Check fields
9596
for field in self.fields:
96-
if isinstance(field, str):
97+
# unicode is a type in python < 3.0, which we need to support (e.g. dev uses unicode_literals)
98+
# noinspection PyUnresolvedReferences
99+
if sys.version_info < (3, 0) and isinstance(field, unicode) or isinstance(field, str):
97100
attr = field
98101
name = field
99102
elif isinstance(field, (list, tuple)) and len(field) == 2:
100103
attr = field[0]
101104
name = field[1]
102105
else:
103106
raise AlgoliaIndexError(
104-
'Invalid fields syntax: {}'.format(field))
107+
'Invalid fields syntax: {} (type: {})'.format(field, type(field)))
105108

106109
self.__translate_fields[attr] = name
107110
if attr in all_model_fields:

0 commit comments

Comments
 (0)