#3387 closed (worksforme)
UnicodeEncodeError on contains and icontains
Reported by: | Gacha | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
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 |
Description
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/__init__.py in <lambda>(x) 23 24 # prepares a value for use in a LIKE query ---> 25 prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 26 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)
Change History (5)
by , 18 years ago
Attachment: | correction.diff added |
---|
comment:1 by , 18 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Resolution: | → worksforme |
Status: | new → closed |
comment:2 by , 18 years ago
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:4 by , 18 years ago
Needs tests: | set |
---|
This is a duplicate of #2489, our general unicodification ticket ...
Note:
See TracTickets
for help on using tickets.
Patch replaces the str() function with unicode() function in django/db/models/fields/init.py at 25 line.