Mark Anthony Vale
Mark Anthony Vale

Reputation: 43

"maximum recursion depth exceeded" trying to call an overloaded function

I'm setting up a custom user authentication, and when I try to create a superuser in powershell it gives me an error " [Previous line repeated 986 more times] RecursionError: maximum recursion depth exceeded" which is referring to my create_superuser()

models.py

def create_superuser(self, username, password=None):
    user = self.create_superuser(
        username,
        password = password,
        is_staff = True,
        is_admin = True

    )
    user.save(using=self._db)
    return user

Upvotes: 1

Views: 974

Answers (2)

create super user is create user forcing password

class UserProfileManager(BaseUserManager):
    """ Manager para perfiles de usuario """
    def create_user(self, username, password=None):
        """ Crear Nuevo UserProfile """
        if not username:
            raise ValueError('username!!!')
        #email= self.normalize_email(email)
        user = self.model(username=uername)
        user.set_password(password)
        user.save(using=self._db)

        return user

    def create_superuser(self, username, password): 
        user = self.create_user(username=username, 
                            password = password,
                            is_staff=True,
                            is_admin = True)
        user.save(using=self._db)
        return user

Upvotes: 0

ivan_pozdeev
ivan_pozdeev

Reputation: 36008

It looks like you want to call an overloaded function.

In Python, there's no function overloading. Instead, a function can have a flexible signature (optional arguments, receiving any arguments via *args and **kwargs). If you define two functions with the same name in the same scope, the one encountered later by the interpreter will simply replace the former.

So, you need to consolidate your two functions into one with a flexible signature. (Nothing prevents you from splitting off helper functions or anything under the hood, but they need to have different names).

Upvotes: 1

Related Questions