#19404 closed Bug (worksforme)
Updating User's email in Admin fails if email already exists
Reported by: | Val Neekman | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.5-beta-1 |
Severity: | Normal | Keywords: | duplicate email UserChangeForm Admin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you had two users with different email addresses, then changed email address of User #1 via the admin page by setting it to that of User #2, then you would get this error:
django/contrib/auth/hashers.py", line 135, in identify_hasher
if len(encoded) == 32 and '$' not in encoded:
TypeError: object of type 'NoneType' has no len()
The above is a simple scenario just to create the error. In real life, with thousands of emails, one wouldn't know if an email is duplicate or not.
An error message could be raised here instead of the above error message that is not that intuitive for the above case.
Change History (5)
comment:1 by , 12 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 by , 12 years ago
Replying to russellm:
I can't reproduce this problem.
What's especially weird is that the code you're describing is about password hashing, which has nothing to do with the email address. This suggests that you're doing something different out of the box that you're not telling us about.
If you can provide more specific instructions about *exactly* what you're doing (e.g., if you're using a custom User model, if you're using the admin interface, what python calls you're making), feel free to reopen.
More info
No custom user.
UserAdmin has been modified (reregistered) with the following to check for duplicate email address during creation and change.
UserCreateForm works as expected. However, UserChangeForm results in this issue. (Both forms inherit from Django and update the required fields.
The odd thing is that the error ONLY occurred when the following code raised an error. (app/forms.py ->UserChangeForm)
app/forms.py
class UserChangeForm(DjangoUserChangeForm): def clean_email(self): # Check that email is not duplicate username = self.cleaned_data["username"] email = self.cleaned_data["email"] users = User.objects.filter(email__iexact=email).exclude(username__iexact=username) # if users: # raise forms.ValidationError(_("A user with that email already exists.")) return email.lower()
app/admin.py
class UserAdmin(DjangoUserAdmin): """ Customize Admin """ form = UserChangeForm try: admin.site.unregister(User) except: pass admin.site.register(User, UserAdmin)
comment:4 by , 12 years ago
Could you please test with latest Git code or by applying this commit: [676e4d5497955bd16b06411c02875683bc312621]
comment:5 by , 12 years ago
This is to confirm that the "bug" has been fixed on master (HEAD) currently at: 90d3af380e8efec0301dd91600c6686232de3943
I can't reproduce this problem.
What's especially weird is that the code you're describing is about password hashing, which has nothing to do with the email address. This suggests that you're doing something different out of the box that you're not telling us about.
If you can provide more specific instructions about *exactly* what you're doing (e.g., if you're using a custom User model, if you're using the admin interface, what python calls you're making), feel free to reopen.