Skip to content

Conversation

glopezmartin
Copy link

Without passing the context when creating the serializer you can't access the user in validation. Simply add the context when creating the serializer class fixes the authentication.

@coveralls
Copy link

coveralls commented Oct 9, 2017

Coverage Status

Coverage remained the same at 92.79% when pulling 210aac6 on glamdisju:master into 77f0361 on graphql-python:master.

@glopezmartin
Copy link
Author

I just saw that maybe I'm duplicating issue #228 altough that PR is a more general way of instantiating serializers.

Copy link
Contributor

@spockNinja spockNinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, #228 is more generic and should provide the flexibility needed for this use case without breaking anyone's existing serializers.

Thanks for the PR, but we are going to pursue #228 instead.

@classmethod
def mutate_and_get_payload(cls, root, info, **input):
serializer = cls._meta.serializer_class(data=input)
serializer = cls._meta.serializer_class(data=input, context=getattr(info, 'context', None))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is a chance this might break if someone has overridden their serializer class's __init__ in such a way as to not accept **kwargs. Even then, if they don't pop the context kwarg off before the base DRF Field class is resolved, I think this could cause an error.

@spockNinja
Copy link
Contributor

Duplicate functionality with #228

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