[Answered ]-Unicode errror from Haystack indexing

2πŸ‘

βœ…

In your lib/python2.7/site-packages/haystack/fields.py, convert function (near line 209). Try to add:

if isinstance(value, str):
   value = value.decode("utf-8")

Full class code after change:

class CharField(SearchField):
    field_type = 'string'

    def __init__(self, **kwargs):
        if kwargs.get('facet_class') is None:
            kwargs['facet_class'] = FacetCharField

        super(CharField, self).__init__(**kwargs)

    def prepare(self, obj):
        return self.convert(super(CharField, self).prepare(obj))

    def convert(self, value):
        if value is None:
            return None

        if isinstance(value, str):
            value = value.decode("utf-8")

        return six.text_type(value)
πŸ‘€Satevg

Leave a comment