#21627 closed Bug (fixed)
changepassword command fails with unicode characters
| Reported by: | Jon | Owned by: | Jon |
|---|---|---|---|
| Component: | contrib.auth | Version: | 1.6 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Starting with Django 1.6, the changepassword management command in the auth module fails when the user's name has non-ascii characters.
$ bin/manage changepassword
Traceback (most recent call last):
File "bin/manage", line 69, in <module>
sys.exit(djangorecipe.manage.main('project.settings'))
File "[..]/.eggs/djangorecipe-1.6-py2.7.egg/djangorecipe/manage.py", line 9, in main
management.execute_from_command_line(sys.argv)
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/contrib/auth/management/commands/changepassword.py", line 42, in handle
self.stdout.write("Changing password for user '%s'\n" % u)
File "[..]/.eggs/Django-1.6.1-py2.7.egg/django/core/management/base.py", line 65, in write
if ending and not msg.endswith(ending):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 33: ordinal not in range(128)
Adding from __future__ import unicode_literals to the changepassword.py file seems to fix it.
Change History (6)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Could you also include a regression test and a note in the 1.6.2 release notes as we will backport the fix.
comment:3 by , 12 years ago
It looks like I encountered this error with a custom user model that displayed the first and last name from the
__unicode__ method on the custom User object. So this would not occur with a vanilla Django User object, since it's __str__ method outputs the username, and the username is validated for ASCII only.
I still think this should be fixed though, since the changepassword command can be utilized with custom User models and it worked in Django 1.5.
Looks like the change happened in commit 70a0de37d132e5f1514fb939875f69649f103124, where the username is no longer explicitly used for the output to stdout.
Is it OK to use a Unicode character in the username for the regression test?
I've committed the fix, a test case and a note in the 1.6.2 release notes, let me know if there's anything else:
https://github.com/funkbit/django/tree/ticket_21627
comment:4 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
I'd be happy to create a pull request if this is the correct way to fix this bug.