Django

Code

Ticket #3387 (closed: worksforme)

Opened 2 years ago

Last modified 2 years ago

UnicodeEncodeError on contains and icontains

Reported by: Gacha Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords: UnicodeEncodeError
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

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

correction.diff (216 bytes) - added by Gacha on 01/29/07 06:57:12.

Change History

01/29/07 06:57:12 changed by Gacha

  • attachment correction.diff added.

01/29/07 07:00:51 changed by Gacha

  • status changed from new to closed.
  • needs_better_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.
  • has_patch set to 1.
  • resolution set to worksforme.

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

01/29/07 09:51:40 changed by Michael Radziej <mir@noris.de>

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.

01/29/07 09:52:19 changed by Michael Radziej <mir@noris.de>

Sorry for misspelling your name, Gacha.

01/29/07 20:35:13 changed by Michael Radziej <mir@noris.de>

  • needs_tests set to 1.

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


Add/Change #3387 (UnicodeEncodeError on contains and icontains)




Change Properties
Action