Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25596 closed Bug (fixed)

Can't change user's password in admin when using custom User model

Reported by: user0007 Owned by: Tim Graham
Component: contrib.admin Version: 1.9b1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by user0007)

Django 1.9b1

I'm using custom User model which is defined as:

AUTH_USER_MODEL = 'users.User'

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    'apps.users',
]

When I tried to change user's password (using /admin/users/user/ID/password/) I've got an error:

Traceback:

File "/src/django/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/src/django/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/src/django/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/src/django/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/src/django/django/contrib/admin/sites.py" in inner
  244.             return view(request, *args, **kwargs)

File "/src/django/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/src/django/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)

File "/src/django/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/src/django/django/contrib/auth/admin.py" in user_change_password
  155.                         args=(user.pk,),

File "/src/django/django/core/urlresolvers.py" in reverse
  600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "/src/django/django/core/urlresolvers.py" in _reverse_with_prefix
  508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /panel/users/user/8/password/
Exception Value: Reverse for 'auth_user_change' with arguments '(8,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

django/auth/admin.py:151

reverse(
                        '%s:auth_%s_change' % (
                            self.admin_site.name,
                            user._meta.model_name,
                        ),
                        args=(user.pk,),
                    )

There should not be fixed "auth_" prefix, but something like user._meta.app_name(?)

Change History (6)

comment:1 by user0007, 9 years ago

Description: modified (diff)
Summary: Can't change user's password in DjangoAdminCan't change user's password in DjangoAdmin when using custom User model

comment:2 by Tim Graham, 9 years ago

Severity: NormalRelease blocker
Summary: Can't change user's password in DjangoAdmin when using custom User modelCan't change user's password in admin when using custom User model
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.9a11.9b1

Regression due to 50aa1a790ca66c2a93e0a52e00c53375b269ff49. Looks like hardcoded "auth" should be user._meta.app_label as you suggested.

comment:3 by Tim Graham, 9 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

I'm looking into how to write a regression test for this.

comment:4 by Tim Graham, 9 years ago

Has patch: set

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

Resolution: fixed
Status: assignedclosed

In 5acf203:

Fixed #25596 -- Fixed regression in password change view with custom user model.

The reverse() added in 50aa1a790ca66c2a93e0a52e00c53375b269ff49
crashed on a custom user model.

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

In 0b4d11e1:

[1.9.x] Fixed #25596 -- Fixed regression in password change view with custom user model.

The reverse() added in 50aa1a790ca66c2a93e0a52e00c53375b269ff49
crashed on a custom user model.

Backport of 5acf203db2e9562dbe4073bf85d5043ef3121ea9 from master

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