Opened 18 years ago

Closed 18 years ago

#2554 closed defect (duplicate)

[patch] Django has problems rendering FormFieldWrapper objects when they contain unicode

Reported by: Victor Ng <victor.ng@…> Owned by: hugo
Component: Internationalization Version:
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django throws exceptions when unicode data is rendered through a dropdown box.

Here's a stacktrace:

Traceback (most recent call last):
File "/home/victorng/dev/django/trunk/django/core/handlers/base.py" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/home/victorng/dev/django/trunk/django/db/transaction.py" in _commit_manually
  218. return func(*args, **kw)
File "/home/victorng/dev/django/trunk/django/views/decorators/cache.py" in _cache_controlled
  25. response = viewfunc(request, *args, **kw)
File "/home/victorng/dev/system/monkeybean/trunk/monkeybean/util/action_handler.py" in __call__
  86. result = inst._generic_view(self._appName, self._shortModName, request, values)
File "/home/victorng/dev/system/monkeybean/trunk/monkeybean/util/action_handler.py" in _generic_view
  432. seed_data = self._http_get(request, values)
File "/home/victorng/dev/system/monkeybean/trunk/monkeybean/util/action_handler.py" in _http_get
  419. seed_data = self.get_seed_data(values, {})
File "/home/victorng/dev/system/monkeybean/trunk/monkeybean/travel/views/agent.py" in get_seed_data
  103. form = django.forms.FormWrapper(Agent.AddManipulator(), values, status_messages)
File "/home/victorng/dev/django/trunk/django/db/models/manipulators.py" in __init__
  69. self.fields.extend(f.get_manipulator_fields(self.opts, self, self.change))
File "/home/victorng/dev/django/trunk/django/db/models/fields/__init__.py" in get_manipulator_fields
  226. field_objs, params = self.prepare_field_objs_and_params(manipulator, name_prefix)
File "/home/victorng/dev/django/trunk/django/db/models/fields/related.py" in prepare_field_objs_and_params
  503. params['choices'] = self.get_choices_default()
File "/home/victorng/dev/django/trunk/django/db/models/fields/__init__.py" in get_choices_default
  302. return self.get_choices()
File "/home/victorng/dev/django/trunk/django/db/models/fields/__init__.py" in get_choices
  293. lst = [(getattr(x, self.rel.get_related_field().attname), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]

  UnicodeEncodeError at /travel/agent/
  'ascii' codec can't encode character u'\xc5' in position 0: ordinal not in range(128)

I'm attaching a patch that resolves this problem. Still have to build a unit test for django.

Attachments (1)

r3598_unicode_formfields.patch (2.0 KB ) - added by Victor Ng <victor.ng@…> 18 years ago.
Patch to fix FormFieldWrapper rendering when data includes unicode

Download all attachments as: .zip

Change History (3)

by Victor Ng <victor.ng@…>, 18 years ago

Patch to fix FormFieldWrapper rendering when data includes unicode

comment:1 by Victor Ng <victor.ng@…>, 18 years ago

I'm not sure why, but this only seems to com eup in Postgresql using psycopg2. I can't get the stacktrace to be thrown using sqlite3.

The unicode string I used to cause the exception was u'\xc5LAND ISLANDS' - it's some country in Europe.

vic

comment:2 by Victor Ng <victor.ng@…>, 18 years ago

Resolution: duplicate
Status: newclosed

#2588 supercedes this patch

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