title: django RecursionError : maximum recursion depth exceeded while calling a Python object
body: <p>I have implemented membership by building a custom user model in the django rest framework. By the way, the following error occurs when you code and run the server.</p>
  <blockquote>
  <p>RecursionError : maximum recursion depth exceeded while calling a
  Python object</p>
  </blockquote>
  <p>Here is full traceback</p>
  <pre><code>Traceback (most recent call last):   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\core\handlers\exception.py&quot;, line 34, in inner
      response = get_response(request)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\core\handlers\base.py&quot;, line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\core\handlers\base.py&quot;, line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\views\decorators\csrf.py&quot;, line 54, in wrapped_view
      return view_func(*args, **kwargs)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\views\generic\base.py&quot;, line 71, in view
      return self.dispatch(request, *args, **kwargs)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\rest_framework\views.py&quot;, line 505, in dispatch
      response = self.handle_exception(exc)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\rest_framework\views.py&quot;, line 465, in handle_exception
      self.raise_uncaught_exception(exc)   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\rest_framework\views.py&quot;, line 476, in raise_uncaught_exception
      raise exc   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\rest_framework\views.py&quot;, line 502, in dispatch
      response = handler(request, *args, **kwargs)   File &quot;D:\school\대회 및 프로젝트\CoCo\api\views.py&quot;, line 16, in post
      serializer.save()   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\rest_framework\serializers.py&quot;, line  212, in save
      self.instance = self.create(validated_data)   File &quot;D:\school\대회 및 프로젝트\CoCo\api\serializers.py&quot;, line 61, in create
      return User.objects.create_user(**validate_data)   File &quot;D:\school\대회 및 프로젝트\CoCo\api\models.py&quot;, line 29, in create_user
      user = self.create_user(   File &quot;D:\school\대회 및 프로젝트\CoCo\api\models.py&quot;, line 29, in create_user
      user = self.create_user(   File &quot;D:\school\대회 및 프로젝트\CoCo\api\models.py&quot;, line 29, in create_user
      user = self.create_user(   [Previous line repeated 951 more times]   File &quot;D:\school\대회 및 프로젝트\CoCo\api\models.py&quot;, line 31, in create_user
      email=self.normalize_email(email),   File &quot;D:\school\대회 및 프로젝트\CoCo\venv\lib\site-packages\django\contrib\auth\base_user.py&quot;, line 25, in normalize_email
      email_name, domain_part = email.strip().rsplit('@', 1) RecursionError: maximum recursion depth exceeded while calling a Python object [20/Aug/2020 09:55:57] &quot;POST /auth/signUp HTTP/1.1&quot; 500 3947748
  </code></pre>
  <p>Can I know how to solve this error? Here is my code.</p>
  <p>models.py</p>
  <pre><code>from django.contrib.auth.models import (BaseUserManager, AbstractBaseUser, PermissionsMixin)
  from django.db import models
  from django.utils import timezone
  
  class UserManager (BaseUserManager) :
      def create_user (self, username, email, profile, password=None) :
  
          if username is None :
              raise TypeError('Users should have a username')
  
          if email is None :
              raise TypeError('Users should have a email')
  
          user = self.model(
              username=username,
              email=self.normalize_email(email),
              profile=profile,
          )
          
          user.set_password(password)
          user.save()
          return user
  
      def create_user (self, username, email, profile, password=None) :
  
          if password is None :
              raise TypeError('Password should not be none')
  
          user = self.create_user(
              username=username,
              email=self.normalize_email(email),
              profile=profile,
              password=password
          )
              
          user.create_user(username, email, profile, password)
          user.is_superuser = True
          user.is_staff = True
          user.save()
          return user
  
  class User (AbstractBaseUser, PermissionsMixin) :
      username = models.CharField(max_length=255, unique=True, db_index=True)
      email = models.CharField(max_length=255, unique=True, db_index=True)
      profile = models.ImageField(default='media\default_image.jpeg')
      is_verified = models.BooleanField(default=False)
      is_active = models.BooleanField(default=True)
      is_staff = models.BooleanField(default=True)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
      USERNAME_FIELD = 'email'
      REQUIRED_FIELDS = ['username', 'profile']
  
      objects = UserManager()
  
      def __str__ (self) :
          return self.email
  </code></pre>
  <p>serializers.py</p>
  <pre><code>from .models import User
  from django.contrib.auth.hashers import make_password
  from rest_framework import serializers
  from rest_framework_simplejwt.serializers import TokenObtainPairSerializer, TokenRefreshSerializer
  from rest_framework_simplejwt.tokens import RefreshToken
  from allauth.account import app_settings as allauth_settings
  from allauth.utils import email_address_exists
  from allauth.account.adapter import get_adapter
  from allauth.account.utils import setup_user_email
  from django.utils.translation import ugettext_lazy as _
  from datetime import datetime, timedelta
  
  class Base64ImageField (serializers.ImageField) :
  
      def to_internal_value (self, data) :
          from django.core.files.base import ContentFile
          import base64
          import six
          import uuid
  
          if isinstance(data, six.string_types):
              if 'data:' in data and ';base64,' in data:
                  header, data = data.split(';base64,')
  
              try:
                  decoded_file = base64.b64decode(data)
              except TypeError:
                  self.fail('invalid_image')
  
              file_name = str(uuid.uuid4())[:12]
              file_extension = self.get_file_extension(file_name, decoded_file)
              complete_file_name = &quot;%s.%s&quot; % (file_name, file_extension, )
              data = ContentFile(decoded_file, name=complete_file_name)
  
          return super(Base64ImageField, self).to_internal_value(data)
  
      def get_file_extension (self, file_name, decoded_file) :
          import imghdr
  
          extension = imghdr.what(file_name, decoded_file)
          extension = &quot;jpg&quot; if extension == &quot;jpeg&quot; else extension
  
          return extension
  
  class customRegisterSerializer (serializers.ModelSerializer) :
      password = serializers.CharField(max_length=68, min_length=6, write_only=True)
      profile = Base64ImageField(use_url=True)
      
      class Meta :
          model = User
          fields = ['email', 'username', 'profile', 'password']
  
      def validate (self, attrs) :
          email = attrs.get('email', '')
          username = attrs.get('username', '')
          profile = attrs.get('profile', '')
  
          return attrs
          
      def create (self, validate_data) :
          return User.objects.create_user(**validate_data)
  </code></pre>