Djoser custom serializer being ignored

Ho folks, i’m trying to implement a custom serializer in my Djoser auth to check for duplicate email on sign up. I was going to filter by email and if exists() I can raise a validation error, but can’t even get to that stage as my API call from the frontend always uses the default Djoser serializer. I’m out of ideas on how to solve this or debug what exactly is going on.

I’ve followed Djoser docs to implement custom validation.

Settings.

DJOSER = {
    'USER_CREATE_PASSWORD_RETYPE': True,
    'SERIALIZERS': {
        'user_create': 'core.serializers.CustomUserCreateSerializer',
        'user': 'core.serializers.CustomUserSerializer',
    },
    'PERMISSIONS' : {
        'user_create': ['rest_framework.permissions.AllowAny']
        }
}

Serliazers

class CustomUserCreateSerializer(UserCreateSerializer):
    class Meta(UserCreateSerializer.Meta):
        model = User
        fields = ('id', 'email', 'username', 'password')

    



class CustomUserSerializer(UserSerializer):
    class Meta(UserSerializer.Meta):
        model = User
        fields = ('id', 'email', 'username')

API call from React

async register(userData) {
        try{
            const response = await axiosInstance.post('/auth/users/', userData)
            return response.data
        } catch(error){
          throw error.response.data  
        }
    }

I’ve checked all imports are correct. Checked my project structure, all the simple things, to me it should be implemented.

Any input much appreciated.

    def get_serializer_class(self):
        if self.action == "create":
            if settings.USER_CREATE_PASSWORD_RETYPE:
                return settings.SERIALIZERS.user_create_password_retype
            return settings.SERIALIZERS.user_create
        elif self.action == "destroy" or (
            self.action == "me" and self.request and self.request.method == "DELETE"
        ):

this is from the UserViewSets get serializer class method. When you set
‘USER_CREATE_PASSWORD_RETYPE’: True,

it assigns the default user create serializer. My suggestion is if you created your custom serializer inherited from the default one you can just remove the setting and make sure you include password retype to fields

class CustomUserCreateSerializer(UserCreateSerializer):

password = serializers.CharField(write_only=True, min_length=8)

password_retype = serializers.CharField(write_only=True)



class Meta:

    model = User

    fields = ('email', 'password', 'password_retype', 'first_name', 'last_name')

Ok, thanks for taking the time to have a look at this. I had to write some middleware to check if a user exists but great to know why a custom serializer could not be used.