Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#3387 closed (worksforme)

UnicodeEncodeError on contains and icontains

Reported by: Gacha Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords: UnicodeEncodeError
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


I got UnicodeEncodeError when I try to search with "icontains" and unicode string.

In [26]: Product.objects.filter(name=unicode('Fantasia - ķiršu','utf-8'))
Out[26]: [<Product: Fantasia - ķiršu>]

In [27]: Product.objects.filter(name__icontains=unicode('Fantasia - ķiršu','utf-8'))
exceptions.UnicodeEncodeError                        Traceback (most recent call last)
/home/***/django/db/models/fields/ in <lambda>(x)
     24 # prepares a value for use in a LIKE query
---> 25 prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
     27 # returns the <ul> class for a given radio_admin value

UnicodeEncodeError: 'ascii' codec can't encode character u'\u0137' in position 11: ordinal not in range(128)

Attachments (1)

correction.diff (216 bytes) - added by Gacha 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by Gacha

Attachment: correction.diff added

comment:1 Changed 12 years ago by Gacha

Has patch: set
Patch needs improvement: set
Resolution: worksforme
Status: newclosed

Patch replaces the str() function with unicode() function in django/db/models/fields/ at 25 line.

comment:2 Changed 12 years ago by Michael Radziej <mir@…>

Gaicha, currently you should not use unicode strings within the database API. It is planned to support this in the future, but as long as this has not happened, you'll run into all sorts of problems. Better use utf8-encoded bytestrings.

comment:3 Changed 12 years ago by Michael Radziej <mir@…>

Sorry for misspelling your name, Gacha.

comment:4 Changed 12 years ago by Michael Radziej <mir@…>

Needs tests: set

This is a duplicate of #2489, our general unicodification ticket ...

Note: See TracTickets for help on using tickets.
Back to Top