[Answer]-Duplicate (and empty) user is created using regular account signup

1👍

After diving into the source code, and sprinkle logs everywhere I found the problem was caused by the custom Signup Model Form I use (I could have figured it out but it wasn’t easy).

django-allauth manually saves the user, so in my case the form model default save method does it again and causes the bug.

As pointed out in the docs:

This class (the ACCOUNT_SIGNUP_FORM_CLASS) should implement a def signup(self, request, user) method, where user represents the newly signed up user.

However, the appreciation is quite vague and (at least in my case) it is easy to think that the ACCOUNT_SIGNUP_FORM_CLASS could be a form (whatever the kind).

So, I found two solutions:

  1. Replace the model form with a regular form. However, it is not clearly explained in the docs.
  2. Override the ModelForm’s save method and skip the call to parent’s save method

I implemented the second one, and the form end up as follows:

class SignupForm(UserCreationForm):

    class Meta:
        model = get_user_model()
        fields = ('first_name', 'last_name', 'email')

    def save(self, commit=True):
        return None
👤kiril

Leave a comment