#14525: Bug - exception in messages.info(), etc when using unicode characters.
--------------------------+-------------------------------------------------
 Reporter:  yoyoma        |       Owner:  nobody    
   Status:  new           |   Milestone:            
Component:  Contrib apps  |     Version:  1.2       
 Keywords:  messages      |       Stage:  Unreviewed
Has_patch:  0             |  
--------------------------+-------------------------------------------------
 On http://groups.google.com/group/django-
 developers/browse_thread/thread/2c3b0d0b518d0c2f I reported that Unicode
 values causes an exception when passed into messages.info() (and other 3
 messages methods). In my report, I erroneously suggested that a Unicode
 character in the URL's GET parameters would cause the exception. The
 following example will reproduce the exception (includes extraneous steps
 for the sake of completion):


 == Example: ==


 {{{

 # The following assumes that settings are default, except the for SQLLite3
 database setting, and file path, and the installed apps setting.

 # Model
 class Foo(Model):
     name = models.CharField(max_length=255)

 # Form
 class FooForm(ModelForm):
     class Meta:
         model = Foo

 # View
 def create_foo(request):
     if request.method == 'POST':
         form = FooForm(request.POST)
         if form.is_valid():
             instance = form.save()
             messages.info(request, 'Thanks, {0}.'.format(instance.name))
             return redirect('foo_thanks')
     else:
         form = FooForm()
     data = {
         'form': form,
     }
     context = RequestContext(request, data)
     template = Template("""<html>
             <head>
                 <title>Bug Page</title>
             </head>
             <body>
                 <div>
                     <h1>Type ° (alt + 0176) into the name field, and hit
 submit.</h1>
                     <form action="" method="post" enctype="application/x
 -www-form-urlencoded">{% csrf_token %}
                         {{form.as_p}}
                         <p>
                             <button type="submit">Raise Exception</button>
                         </p>
                     </form>
                 </div>
             </body>
         </html>""")
     output = template.render(context)
     return HttpResponse(output)


 def foo_thanks(request):
     return HttpResponse('No need to render message, as exception occurs
 upon creation.')

 }}}



 == Traceback: ==


 {{{

 UnicodeEncodeError at /create_foo/

 ('ascii', u'\xb0', 0, 1, 'ordinal not in range(128)')

 Request Method:         GET
 Request URL:    http://127.0.0.1:8080/create_foo/
 Django Version:         1.3 pre-alpha SVN-14235
 Exception Type:         UnicodeEncodeError
 Exception Value:

 ('ascii', u'\xb0', 0, 1, 'ordinal not in range(128)')

 Exception Location:     D:\myproject\myapp\views.py in create_foo, line
 XXX
 Python Executable:      C:\Python26\python.exe
 Python Version:         2.6.4

 1) response = callback(request, *callback_args, **callback_kwargs)
 2) messages.info(request, 'Thanks, {0}.'.format(instance.name))

 }}}


 There are only 2 steps in the traceback.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14525>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to