[Fixed]-Custome user serializer giving error on is_valid() โ€“ django

1๐Ÿ‘

โœ…

You have a number of misconceptions here.

Firstly, the password is not hashed because you are not calling any method that hashes it. When you create a user, you must always call create_user, not create; it is the former that hashes the password.

user1 = User.objects.create_user(username='username', email='email@email.com', password='password')

Secondly, the reason user1_s is invalid is clearly explained in the error message: when you want to pass data into a serializer and get a User object out, you need to actually pass a dictionary of data in and not a User object.

So, as a test, this would work:

user1_serialize = UserModelSerializer(user1)
data = user1_serialize.data
user1_deserialize = UserModelSerializer(data=data)
user1_deserialize.is_valid()
๐Ÿ‘คDaniel Roseman

Leave a comment