Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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 Jon, 11 years ago

I'd be happy to create a pull request if this is the correct way to fix this bug.

comment:2 by Tim Graham, 11 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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 Jon, 11 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 Jon, 11 years ago

Owner: changed from nobody to Jon
Status: newassigned

comment:5 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 398642fd9b6e9b4d83baed7b9708ca0cd942540b:

Fixed #21627 -- Added unicode_literals to changepassword command.

Fixed a crash when executing changepassword command when the user object
representation contained non-ASCII characters.

comment:6 by Tim Graham <timograham@…>, 11 years ago

In 0e8138349ef7f30f6042853b10f28be7301c20ca:

[1.6.x] Fixed #21627 -- Added unicode_literals to changepassword command.

Fixed a crash when executing changepassword command when the user object
representation contained non-ASCII characters.

Backport of 398642fd9b from master

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