#19404: Updating User's email in Admin fails if email already exists
-------------------------------------+-------------------------------------
     Reporter:  un33k                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.admin        |                  Version:
     Severity:  Normal               |  1.5-beta-1
     Keywords:  duplicate email      |               Resolution:
  UserChangeForm Admin               |  worksforme
    Has patch:  0                    |             Triage Stage:
  Needs tests:  0                    |  Unreviewed
Easy pickings:  0                    |      Needs documentation:  0
                                     |  Patch needs improvement:  0
                                     |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by un33k):

 Replying to [comment:1 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
 {{{#!python
 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
 {{{#!python
 class UserAdmin(DjangoUserAdmin):
     """ Customize Admin """
     form = UserChangeForm

 try:
     admin.site.unregister(User)
 except:
     pass
 admin.site.register(User, UserAdmin)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19404#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to