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

Access to context fails inside nested serializer #6

Closed
jtrain opened this issue Feb 7, 2017 · 2 comments
Closed

Access to context fails inside nested serializer #6

jtrain opened this issue Feb 7, 2017 · 2 comments

Comments

@jtrain
Copy link
Collaborator

jtrain commented Feb 7, 2017

As discussed in #5 a DynamicFieldMixin-ed serializer that accesses context will fail when used as a nested serializer.

I found this issue when I was re-using a serializer as a nested serializer, and that serializer relies on context['request'] to build a url for one of its fields.

Without fixing drf-dynamic-fields to allow nested serializers, there are a number of work arounds:

  1. You could just have two separate serializers, one for nesting and one for normal views.
  2. The nested serializer can manually find the correct context by chasing the parent fields up the tree until it finds the one with context set.

I used 2) for a while before deciding it was better to fix the underlying issue.

@jtrain
Copy link
Collaborator Author

jtrain commented Mar 15, 2017

#8 This one has the PR now for this.

@dbrgn
Copy link
Owner

dbrgn commented Mar 19, 2017

Fixed by #10 I think.

@dbrgn dbrgn closed this as completed Mar 19, 2017
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

No branches or pull requests

2 participants