﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14525	Bug - exception in messages.info(), etc when using unicode characters.	Michael Angeletti	nobody	"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."		closed	Contrib apps	1.2		invalid	messages		Unreviewed	0	0	0	0	0	0
