Opened 16 years ago

Closed 15 years ago

#8916 closed (invalid)

admin auth change password not working

Reported by: ask@… Owned by: nobody
Component: contrib.admin Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Karen Tracey)

Trying to access the change password form in auth admin will cause a "ValueError"

Trace is below

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/password/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.databrowse',
 'pressDB.press',
 'pressDB.ext']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  158.                 return self.model_page(request, *url.split('/', 2))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page
  177.         return admin_obj(request, rest_of_url)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/options.py" in __call__
  197.             return self.change_view(request, unquote(url))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
  238.                 res = func(*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  557.             obj = model._default_manager.get(pk=object_id)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/manager.py" in get
  93.         return self.get_query_set().get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py" in get
  297.         clone = self.filter(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py" in filter
  483.         return self._filter_or_exclude(False, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py" in _filter_or_exclude
  501.             clone.query.add_q(Q(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py" in add_q
  1224.                             can_reuse=used_aliases)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py" in add_filter
  1167.         self.where.add((alias, col, field, lookup_type, value), connector)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/where.py" in add
  48.                 params = field.get_db_prep_lookup(lookup_type, value)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  202.             return [self.get_db_prep_value(value)]
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  353.         return int(value)

Exception Type: ValueError at /admin/auth/user/1/password/
Exception Value: invalid literal for int() with base 10: '1/password'

Attachments (1)

change password form ERROR.PNG (75.3 KB ) - added by liybrn 16 years ago.
when click "change password form", Wrong

Download all attachments as: .zip

Change History (17)

comment:1 by ask@…, 16 years ago

Resolution: invalid
Status: newclosed

No error, i just need to think

comment:2 by django@…, 16 years ago

Component: Authenticationdjango.contrib.admin
Resolution: invalid
Status: closedreopened

I am having the same problem on both 1.0 and trunk.

comment:3 by Karen Tracey, 16 years ago

Description: modified (diff)

comment:4 by Karen Tracey, 16 years ago

Resolution: worksforme
Status: reopenedclosed

Really the exact same error with the exact same traceback? Because the original poster seemed to come to the conclusion it was a user error. And I can do a get on the change password form in admin using current trunk, so there's something different about what you are doing. Please elaborate on how you have configured things and what exact error you get, including traceback.

comment:5 by django@…, 16 years ago

Resolution: worksforme
Status: closedreopened

Sure looks the same to me. The new admin seems to work fine for me otherwise. My regular password changing forms work fine, btw.

Traceback (most recent call last):

File "/home/dynnetwork/lib/python2.5/django/core/handlers/base.py", line 86, in get_response

response = callback(request, *callback_args, callback_kwargs)

File "/home/dynnetwork/lib/python2.5/django/contrib/admin/sites.py", line 157, in root

return self.model_page(request, *url.split('/', 2))

File "/home/dynnetwork/lib/python2.5/django/views/decorators/cache.py", line 44, in _wrapped_view_func

response = view_func(request, *args, kwargs)

File "/home/dynnetwork/lib/python2.5/django/contrib/admin/sites.py", line 176, in model_page

return admin_obj(request, rest_of_url)

File "/home/dynnetwork/lib/python2.5/django/contrib/admin/options.py", line 197, in call

return self.change_view(request, unquote(url))

File "/home/dynnetwork/lib/python2.5/django/db/transaction.py", line 238, in _commit_on_success

res = func(*args, kw)

File "/home/dynnetwork/lib/python2.5/django/contrib/admin/options.py", line 548, in change_view

obj = model._default_manager.get(pk=object_id)

File "/home/dynnetwork/lib/python2.5/django/db/models/manager.py", line 93, in get

return self.get_query_set().get(*args, kwargs)

File "/home/dynnetwork/lib/python2.5/django/db/models/query.py", line 303, in get

clone = self.filter(*args, kwargs)

File "/home/dynnetwork/lib/python2.5/django/db/models/query.py", line 489, in filter

return self._filter_or_exclude(False, *args, kwargs)

File "/home/dynnetwork/lib/python2.5/django/db/models/query.py", line 507, in _filter_or_exclude

clone.query.add_q(Q(*args, kwargs))

File "/home/dynnetwork/lib/python2.5/django/db/models/sql/query.py", line 1248, in add_q

can_reuse=used_aliases)

File "/home/dynnetwork/lib/python2.5/django/db/models/sql/query.py", line 1191, in add_filter

self.where.add((alias, col, field, lookup_type, value), connector)

File "/home/dynnetwork/lib/python2.5/django/db/models/sql/where.py", line 48, in add

params = field.get_db_prep_lookup(lookup_type, value)

File "/home/dynnetwork/lib/python2.5/django/db/models/fields/init.py", line 202, in get_db_prep_lookup

return [self.get_db_prep_value(value)]

File "/home/dynnetwork/lib/python2.5/django/db/models/fields/init.py", line 353, in get_db_prep_value

return int(value)

ValueError: invalid literal for int() with base 10: '12/password'

comment:6 by Karen Tracey, 16 years ago

For future reference please enclose traceback in triple braces ({{{ }}}) so they format properly.

Pity the original poster did not explain what was they did to cause this error, because you seem to have done the same thing. Have you done something to customize the Admin handling for the User object? Because the traceback shows you are calling into the ModelAdmin __call__ function in django/contrib/admin/options.py instead of the one for UserAdmin in django/contrib/auth/admin.py.

Really, this is not a bug in Django, this works out of the box. You've done something with your config to cause this though I'm not sure exactly what. It's really more properly pursued on django-users but it'd be nice to get a resolution noted in this ticket as to how users can cause this. So, please share more details of your config, particularly any admin.site.register calls you have.

comment:7 by benshapiro, 16 years ago

Aha! I think we're on to something here. I had the following:

from spackle.spackle1.models import *
from django.contrib import admin

admin.site.register(School)
admin.site.register(Cohort)
admin.site.register(PersonAggregation)
admin.site.register(Course)

class PersonInline(admin.StackedInline):
	model=Person
	max_num=1
	extra=1
	
class UserOptions(admin.ModelAdmin):
	inlines = [PersonInline,]

admin.site.unregister(User)
admin.site.register(User, UserOptions)

admin.site.register(Person)

It works fine, now that I've taken out the UserOptions stuff.

So, what's the trick in newforms admin to doing what I'm trying to do here? Is there a recommended way to do this?

Ben

comment:8 by Karen Tracey, 16 years ago

I assume you're supposed to add:

from django.contrib.auth.admin import UserAdmin

and change:

class UserOptions(admin.ModelAdmin):

to

class UserOptions(UserAdmin):

That way your customized User admin doesn't lose the code already in UserAdmin, you just override or add what you want.

comment:9 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: reopenedclosed

I agree with Karen; there's no Django bug here. Subclassing has to be done carefully.

(Karen: if there's some other reason you've left this open, please reopen. Looks like the reported problem is a non-issue, though).

comment:10 by aaron@…, 16 years ago

I am getting this same error on 2 unrelated sites I just recently upgraded to django 1.0. I don't have any admin class registered with my user model on either site, only:

admin_site = admin.AdminSite()
admin_site.register(User)

I tried importing the UserAdmin as recommended above and registering with the User model to the admin site, but I am still getting the error described above on 2 sites I've tested now:

Environment:

Request Method: GET
Request URL: http://aaronfay.ca/admin/auth/user/1/password/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.comments',
 'django.contrib.contenttypes',
 'django.contrib.markup',
 'django.contrib.sessions',
 'django.contrib.sites',
 'common',
 'region',
 'profile',
 'tagging']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'middleware.StatsMiddleware')


Traceback:
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/core/handlers/base.py" in get_response
  81.                 response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/home/aaronfay/webapps/aaronfay/aaronfay/middleware.py" in process_view
  20.         response = view_func(request, *view_args, **view_kwargs)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/contrib/admin/sites.py" in root
  158.                 return self.model_page(request, *url.split('/', 2))
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/contrib/admin/sites.py" in model_page
  177.         return admin_obj(request, rest_of_url)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/contrib/admin/options.py" in __call__
  197.             return self.change_view(request, unquote(url))
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/transaction.py" in _commit_on_success
  238.                 res = func(*args, **kw)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/contrib/admin/options.py" in change_view
  557.             obj = model._default_manager.get(pk=object_id)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/manager.py" in get
  93.         return self.get_query_set().get(*args, **kwargs)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/query.py" in get
  297.         clone = self.filter(*args, **kwargs)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/query.py" in filter
  483.         return self._filter_or_exclude(False, *args, **kwargs)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/query.py" in _filter_or_exclude
  501.             clone.query.add_q(Q(*args, **kwargs))
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/sql/query.py" in add_q
  1224.                             can_reuse=used_aliases)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/sql/query.py" in add_filter
  1167.         self.where.add((alias, col, field, lookup_type, value), connector)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/sql/where.py" in add
  48.                 params = field.get_db_prep_lookup(lookup_type, value)
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/fields/__init__.py" in get_db_prep_lookup
  202.             return [self.get_db_prep_value(value)]
File "/home/aaronfay/webapps/aaronfay/lib/python2.5/django/db/models/fields/__init__.py" in get_db_prep_value
  353.         return int(value)

Exception Type: ValueError at /admin/auth/user/1/password/
Exception Value: invalid literal for int() with base 10: '1/password'

I'm not certain I should reopen the ticket, but I wanted to let you know I am getting the error also. The 2 sites I tested are on 2 separate servers, both with Django 1.0 release.

comment:11 by Brian Rosner, 16 years ago

You are not showing how you registered with UserAdmin. The code you displayed that you *only* have is wrong. That uses a default ModelAdmin which will lead to that error.

by liybrn, 16 years ago

when click "change password form", Wrong

comment:12 by donkeyhotty, 16 years ago

Hi, I'm leaving this ticket closed because I'm a complete newb, and I don't have the experience to figure out whether this is my fault or not. But for what it's worth I seem to have exactly the same problem as a few other people here. Traceback is below. It's what I get when I click the "change password form" link in the Django Administration when editing a User. Besides adding

admin.site.register(User)

admin.site.register(Group)

to the admin.py in my app, I haven't done anything else to monkey with User. At the top of the same file, I import:

from django.contrib import admin

from models import *

from datetime import datetime

from django.contrib.auth.models import Group, User

That's it.

After googling, I've found that if I create a password in the Python interpreter like this:

import md5


md5.new('test').hexdigest()


'098f6bcd4621d373cade4e832627b4f6'

and then paste 098f6bcd4621d373cade4e832627b4f6 into the field, when I come back after saving it, it's been converted to a sha encrypted password and I can log in successfully with the new password. But a) this isn't feasible for regular users of the admin panel, and b) the "change password form" link remains broken in any case.

My apologies in advance if I've left something important out.

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/auth/user/2/password/
Django Version: 1.1 pre-alpha SVN-9613
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.flatpages',
 'd_utilities.oofle',
 'adminStuff']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in root
  157.                 return self.model_page(request, *url.split('/', 2))
File "C:\Python25\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in model_page
  176.         return admin_obj(request, rest_of_url)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py" in __call__
  197.             return self.change_view(request, unquote(url))
File "C:\Python25\lib\site-packages\django\db\transaction.py" in _commit_on_success
  238.                 res = func(*args, **kw)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py" in change_view
  548.             obj = model._default_manager.get(pk=object_id)
File "C:\Python25\lib\site-packages\django\db\models\manager.py" in get
  93.         return self.get_query_set().get(*args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\models\query.py" in get
  303.         clone = self.filter(*args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\models\query.py" in filter
  489.         return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
  507.             clone.query.add_q(Q(*args, **kwargs))
File "C:\Python25\lib\site-packages\django\db\models\sql\query.py" in add_q
  1255.                             can_reuse=used_aliases)
File "C:\Python25\lib\site-packages\django\db\models\sql\query.py" in add_filter
  1198.         self.where.add((alias, col, field, lookup_type, value), connector)
File "C:\Python25\lib\site-packages\django\db\models\sql\where.py" in add
  48.                 params = field.get_db_prep_lookup(lookup_type, value)
File "C:\Python25\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_lookup
  202.             return [self.get_db_prep_value(value)]
File "C:\Python25\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_value
  353.         return int(value)

Exception Type: ValueError at /admin/auth/user/2/password/
Exception Value: invalid literal for int() with base 10: '2/password'

comment:13 by Karen Tracey, 16 years ago

Replying to donkeyhotty:

Hi, I'm leaving this ticket closed because I'm a complete newb, and I don't have the experience to figure out whether this is my fault or not. But for what it's worth I seem to have exactly the same problem as a few other people here. Traceback is below. It's what I get when I click the "change password form" link in the Django Administration when editing a User. Besides adding

admin.site.register(User)

admin.site.register(Group)

Why are you registering User and Group to admin in your own app? If you use admin.autodiscover() in your urls.py then User and Group will be registered with the custom admin models defined for them by default. If you are overriding them in some way you need to inherit from the cusom models defined in /django/contrib/auth/admin.py, not ModelAdmin, because the password stuff, for instance, is added in the custom model. So the problem is resulting because you are including 'admin.site.register(User)' in your own code. That registration will not support changing passwords as the default one set up in django/contrib/auth/admin.py does.

If you have follow-up questions, the django-users list is a better place for questions like this.

comment:14 by Dave Naffziger, 16 years ago

I stumbled across this ticket a little bit ago and finally came back to fix my problem.

For future reference:

Before (code that generated this error):

from django.contrib import admin

class MyUserAdmin(admin.ModelAdmin):
    list_display = ('username', 'email', 'date_joined', 'last_login', 'is_active')
    form = MyUserAdminForm

After (code that works fine):

from django.contrib.auth.admin import UserAdmin 

class MyUserAdmin(UserAdmin):
    list_display = ('username', 'email', 'date_joined', 'last_login', 'is_active')
    form = MyUserAdminForm

I hope others find this helpful.

comment:15 by phu, 15 years ago

Resolution: invalid
Status: closedreopened
Version: 1.01.1-beta-1

This error is reproducible in 1.1 beta 1 (it is not a result of the aforementioned subclassing missteps):

  1. On a basic installation, enable the admin interface, set up a basic DB (sqlite3 and mysql tested, should not matter), and sync.
  2. Create an admin user.
  3. Run runserver; enter the admin interface (obviously that's all that will be available) and edit your previously-created admin user.
  • The 'change password form' link under the Password field (containing the hash) works.
  • The 'Change password' link next to 'Welcome, [username]' in the upper right corner leads to this 'invalid literal' page.

Working:
/admin/auth/user/1/password/
Not working:
/admin/auth/user/1/admin/password_change/

Unfortunately, I don't have time to dig through the admin code, so I don't know what the 'password_change' form looks like... if it's pointing to the same place as the working 'password' link, this may just be a quick template change.

comment:16 by Alex Gaynor, 15 years ago

Resolution: invalid
Status: reopenedclosed

That's because of bug #10061, closing this again.

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