-
Notifications
You must be signed in to change notification settings - Fork 29
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
Set dynamic field for GET method only #30
base: master
Are you sure you want to change the base?
Conversation
Set dynamic field for get method only
Are you able to show a test case for the problem you were seeing? It sounds like you are POSTing to an endpoint but also adding the |
e.g. |
Yes, i think post/put/patch methods should be ignored for fields query params. |
Correct me if I'm wrong, but a valid use-case might be someone who has expensive fields, and wants to POST their content, and only get back a subset of the fields (excluding the expensive ones). This would prevent that scenario completely. Is there a reason that you are inserting the |
BTW seems somewhat related to this closed branch: |
Hm, I somewhat agree that the response to POST requests should not be filtered. This could have unintended side effects and I think the behavior is generally undefined / unclear (this can be seen by us discussing about whether or not the response should be filtered or not). @jtrain could you agree to that? @dwisulfahnur could you maybe add a test? e.g. an endpoint that returns JSON for both GET and POST, but where only GET is filtered. The tests are here. |
I don't think anyone would be relying on the current behaviour, considering it is very limited (fields are filtered for both to_internal and to_representation). And I (in my own code) don't use GET params for any of our POST requests etc. So I'm OK if you want to cut the functionality. We should have a test for it though, so people know it was intentional too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dwisulfahnur thanks for bringing this up!
I'm happy to accept this PR if you add a test and update the first sentence in the README like this:
This package provides a serializer mixin that allows the user to dynamically select only a subset of fields per resource on GET requests.
Hello @dbrgn Thanks for your reply, |
@dwisulfahnur yes its true, we could do that. However its much simpler overall to ignore POST entirely and say we don't handle them. We've had one other pull request asking for this functionality (filter read fields, not POST ones). But otherwise no one asking for it. And when we release this we should bump the version for breaking change? |
I actually can't quite follow regarding the
Yep, since we're below 1.0.0, according to SemVer 0.4.0 would be the correct next version. But you don't have to include the bump in your PR, I prefer always bumping before a release (this avoids conflicts between multiple PRs). |
I have try to using dynamic fields in POST method and i got an error caused there is a required field are not on the fields selection. I think this PR should be handle the problem.
Thanks