Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#10877 closed (worksforme)

search_fields raise TypeError if field names are given as unicode objects.

Reported by: Cliff Dyer Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you specify field names in search_fields as unicode objects, when you search you get the following exception:

  Exception Type:  	TypeError
  Exception Value: 	__init__() keywords must be strings
  Exception Location: 	/usr/lib/python2.4/site-packages/django/contrib/admin/views/ in get_query_set, line 230

For example, the following code raises this TypeError:

from django.contrib import admin
class MyAdmin(admin.ModelAdmin)
    search_fields = [u'title']

This can be worked around by converting such unicode specified field names to strings:

    search_fields = [str(field) for field in unicode_search_fields]

Other similar specifiers, such as 'list_filter' and 'exclude' handle unicode objects the same way they handle strings.

Change History (3)

comment:1 Changed 10 years ago by Alex Gaynor

What version of Django are you using? Specifically if you are using 1.0.2 or less this has been fixed since(r10510).

comment:2 Changed 10 years ago by Alex Gaynor

Resolution: worksforme
Status: newclosed

Closing as worksforme since no new information has come to light.

comment:3 Changed 10 years ago by Cliff Dyer

Just found this searching for my username. Somehow I never saw the updates. I was indeed using 1.0.2 when I found this bug, for the record.

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