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

Pass in Context for ToolSerializer #3455

Closed
ilan-gold opened this issue Oct 1, 2019 · 3 comments
Closed

Pass in Context for ToolSerializer #3455

ilan-gold opened this issue Oct 1, 2019 · 3 comments

Comments

@ilan-gold
Copy link
Member

ilan-gold commented Oct 1, 2019

Noticed while working on #2619

  • Version of the web browser and OS:
  • Environment where the error occurred (Vagrant VM and site conf mode or AWS instance): Any

Steps to reproduce

Please list all the actions and the input data used:

  1. Launch an analysis and look in the logs for a caught error about the user being None
    def get_is_owner(self, data_set):

Observed behavior

  • AttribtueError

Expected behavior

  • Our handling of context should be {'request':request} here to prevent the error
@jkmarx
Copy link
Member

jkmarx commented Oct 1, 2019

@ilan-gold How are you/user hitting this error? Could you give a specific example. What do the DRF docs say? In general, I thought we wanted to minimize passing the context to the serializer but we have some use cases.

@ilan-gold
Copy link
Member Author

ilan-gold commented Oct 1, 2019

@jkmarx https://github.com/refinery-platform/refinery-platform/blob/develop/refinery/tool_manager/views.py#L118 calls DatSetSerializer (via ToolSerliazer) without context. When I was looking in to it, I noticed that the convention was inconsistent - the example on DRF's website uses context={'request' = request} and i think this makes sense. but we, for example, do something different sometimes, like in

serializer = ExtendedGroupSerializer(member_groups,
)

@jkmarx
Copy link
Member

jkmarx commented Oct 1, 2019

@ilan-gold For the data_set example above, the context required more than the request in the context.

https://www.django-rest-framework.org/api-guide/serializers/#including-extra-context

From the docs, "You can provide arbitrary additional context by passing a context argument when instantiating the serializer. " The purpose of context is to provide additional information not necessarily the request.

@ilan-gold ilan-gold changed the title Make Consistent The Use of Context in DRF Pass in Context for ToolSerializer Oct 2, 2019
@jkmarx jkmarx closed this as completed Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants