pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.51k stars 3.03k forks source link

Django Allauth: EmailAddress Assertion Error when signing up #1304

Closed bkoatz closed 8 years ago

bkoatz commented 8 years ago

I'm on Django 1.8.4, allauth 0.24.1, and I receive this error when after calling form.save on an instance of allauth's SignupForm

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Library/Python/2.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/views.py", line 174, in dispatch
    return super(SignupView, self).dispatch(request, *args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/views.py", line 69, in dispatch
    **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/views.py", line 152, in dispatch
    **kwargs)
  File "/Library/Python/2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/views.py", line 85, in post
    response = self.form_valid(form)
  File "/Users/bkoatz/Git Repos/tt/apps/musician/views.py", line 89, in form_valid
    user = form.save(self.request)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/forms.py", line 310, in save
    setup_user_email(request, user, [])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/allauth/account/utils.py", line 240, in setup_user_email
    assert EmailAddress.objects.filter(user=user).count() == 0
AssertionError

It seems like maybe an EmailAddress (allauth model) is getting created early, but all I'm doing is calling form.save within form_valid, which as far as I know is standard Django practice. Any help? Thanks!

PS Same as stack overflow question I posted here: http://stackoverflow.com/questions/35542661/django-allauth-emailaddress-assertion-error-when-signing-up

pennersr commented 8 years ago

It appears this is an issue in your setup, not in allauth... do you happen to use a custom signup form, and is that a ModelForm? Make sure it is a regular form instead. It is not feasible for me to debug project specific issues... so I'll have to close this.

bkoatz commented 8 years ago

It's a custom signup form of the type SignupForm, within a SignupView, both from allauth.account. Thanks for the help!

pennersr commented 8 years ago

Don't point ACCOUNT_SIGNUP_FORM_CLASS to a SignupForm.. it should really be a regular form (derived from forms.Form) with just your additional fields.