Code

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3387 closed (worksforme)

UnicodeEncodeError on contains and icontains

Reported by: Gacha Owned by: adrian
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: UI/UX:

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)

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

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by Gacha

comment:1 Changed 7 years ago by Gacha

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Resolution set to worksforme
  • Status changed from new to closed

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

comment:2 Changed 7 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 7 years ago by Michael Radziej <mir@…>

Sorry for misspelling your name, Gacha.

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

  • Needs tests set

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.