Opened 14 years ago

Closed 13 years ago

#3266 closed defect (duplicate)

RadioSelect broken -- UnicodeDecodeError

Reported by: Honza Král <Honza.Kral@…> Owned by: Adrian Holovaty
Component: Forms Version:
Severity: normal Keywords:
Cc: Honza.Kral@…, jl@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


test application:


{{ form }}

# -*- coding: utf-8 -*-
from django import newforms as forms         
from django.shortcuts import *               
class TestForm( forms.Form ):
    sel_field = forms.ChoiceField(                                                                                                                                                                            
                    label=Žluťoučký kůň',  
                        ( u'Žluťoučký', u'úpěl ďábelské ódy' ),
                        ( u'Žluťoučký', u'úpěl ďábelské ódy' ) 
def test_view( request ):
    return render_to_response( "test_form.html", { 'form' : TestForm() } )                                                                                

from django.conf.urls.defaults import *
urlpatterns = patterns('',
    (r'^test_form/$', 'myTest.views.test_view' ),                                                                                                                         

If you change the widget to Select, everything works OK, with the RadioSelect it fails on UnicodeDecode error.
Unfortunately I do not understand UNICODE in python (I am fairly new to the language) so I cannot fix it myself without guessing.

Change History (7)

comment:1 Changed 14 years ago by jl@…

Cc: jl@… added

Same error here!
I came across the UnicodeDecodeError when I tried to fetch data for dynamic choices that contains non-ascii characters.
For now I solved it by encoding the special characters as html entities which is lame. Especially because the same choices work for widget.Select.

Please help
This bug renders widget.RadioSelect pointless for other languages than non-ascii languages and i18n'ed sites.

comment:2 Changed 14 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [4304]) Fixed #3266 -- newforms: Made RadioSelect accept funky characters. Thanks for reporting, Honza Kral

comment:3 Changed 13 years ago by…

Resolution: fixed
Status: closedreopened

This code still raises UnicodeDecodeError.


return self.__unicode__().encode(settings.DEFAULT_CHARSET)


return self.__unicode__()

in StrAndUnicode fixes this error.

comment:4 Changed 13 years ago by adurdin@…

Is this a duplicate of #3597?

comment:5 Changed 13 years ago by Gary Wilson <gary.wilson@…>

Can anyone confirm that this has been fixed as of [4924]?

comment:6 Changed 13 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedAccepted

comment:7 Changed 13 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: reopenedclosed

Yes, this is a dupe of #3597. The test included in that patch is basically the same as the example given here. I've improved that test slightly in [5226] (on the unicode branch only, but will eventually be merged back to trunk) to more or less match this example exactly and it still passes.

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