question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Serializer Problem

See original GitHub issue

I am using custom Registration serializer, here it is: #settings.py REST_AUTH_REGISTER_SERIALIZERS = { 'REGISTER_SERIALIZER': 'api.serializers.MyRegisterSerializer' }

#serializers.py

class MyRegisterSerializer(RegisterSerializer):
    first_name = serializers.CharField()
    last_name = serializers.CharField()
    password = serializers.CharField(write_only=True)
    password1 = password2 = password
    
    def validate(self, data):
        return data

    def get_cleaned_data(self):
        super(MyRegisterSerializer, self).get_cleaned_data()
        return {
            'username': self.validated_data.get('username', ''),
            'password': self.validated_data.get('password', ''),
            'email': self.validated_data.get('email', ''),
            'first_name': self.validated_data.get('first_name', ''),
            'last_name': self.validated_data.get('last_name', '')
        }

Issue is : i am getting an unknown ! prepended to my password, hence forth my password is unrecogonized during login.

With using MYREGISTERSERIALIZER : password = !HnBxoehpig…

without using MYREGISTERSERIALIZER: password = pbkdf2_sha256… i know password depends on many factors (SALT, Datetime and so), but my presumption is may this is the issue that causing me login problems as all the signups done with custom serializer has this ! prepended.

Kindly check the root cause.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
deepak1725commented, May 14, 2018

@shakeelcse09

from rest_auth.registration.serializers import RegisterSerializer

class MyRegisterSerializer(RegisterSerializer):
    first_name = serializers.CharField()
    last_name = serializers.CharField()

    def get_cleaned_data(self):
        super(MyRegisterSerializer, self).get_cleaned_data()
        return {
            'username': self.validated_data.get('username', ''),
            'password1': self.validated_data.get('password1', ''),
            'email': self.validated_data.get('email', ''),
            'first_name': self.validated_data.get('first_name', ''),
            'last_name': self.validated_data.get('last_name', '')
        }

For Detailed Code, here it is https://github.com/deepak1725/djangular/blob/master/api/serializers.py

1reaction
deven769commented, Dec 8, 2019

thank you deepak1725 it worked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Serializer Not Called For Array Or Collection Types
You need to properly register your custom serialiser using MixIn feature. Instead of annotating property, you need to annotate class which ...
Read more >
@JsonUnwrapped does not work with a custom Serializer ...
Since now, my Serializer works fine and everything is good. The problem is with another entity "Order" which has Payment as a property...
Read more >
Calling Default Serializer from Custom Serializer in Jackson
A possible workaround is using BeanSerializerModifier to store the default serializer for the type Folder before Jackson internally overrides it ...
Read more >
Serialization and Deserialization Issues in Spring REST
In Spring REST projects a custom implementation of MappingJackson2HttpMessageConverter helps to create the custom ObjectMapper , as seen below.
Read more >
Spring Custom Serializers with @JsonIdentityInfo - NEX Softsys
If the object is complex and needs to customize the serialization/ deserialization then we need to write Custom Serializer which extends ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found