Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use data instead of validated data #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Use data instead of validated data #120

wants to merge 1 commit into from

Conversation

jonathan-s
Copy link

Because validated_data is used instead of data you can't use your own serializer which uses a custom to_representation method. I was banging my head against this for a while.

@davesque
Copy link
Member

Looks like the test suite is failing. Can you figure out why that's happening?

Because `validated_data` is used instead of `data` you can't use your own serializer which uses a custom `to_representation` method. I was banging my head against this for a while.
@jonathan-s
Copy link
Author

@davesque I checked it out and it was because the data changes in the validate method (ie, from username & password to token). Normally it expects that the same data that is being validated is also shown in represented. Since that isn't the case I'm adding a custom to_representation method that just passes on the data that has been validated.

@davesque
Copy link
Member

Great, thanks for checking that out. I'll try and find some time today to do a bit of diligence on my end then merge this.

@jonathan-s
Copy link
Author

jonathan-s commented May 20, 2019 via email

@jonathan-s
Copy link
Author

@davesque Just a reminder for this PR.

@rohanahata
Copy link

@davesque @jonathan-s any progress on this?

@jonathan-s
Copy link
Author

It's in davesque's hand.

@rohanahata
Copy link

@davesque

@davesque
Copy link
Member

Sorry this has sat so long without any attention. I was a bit concerned that the little change might have unexpected consequences. So I meant to take a closer look but haven't really had any time to do that. Can you explain a bit more about why using validated_data prevents people from using their own serializer with a custom to_representation? I just want to make sure we're making the right change to solve the problem.

@jonathan-s
Copy link
Author

@davesque If you look at how things are expected from the rest_framework it's using serializer.data rather than serializer.validated_data. https://github.com/encode/django-rest-framework/blob/0407a0df8a16fdac94bbd08d49143a74a88001cd/rest_framework/mixins.py#L75

I can't exactly remember what the errors were since it was such a long time ago now. @rohanahata perhaps you can fill me in since it seems like you're facing this issue right now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants