-
Notifications
You must be signed in to change notification settings - Fork 81
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
Content Negotiation Improvement Proposal #1
Conversation
This is a great idea (and your DEP seems well written), and I would like to help (if possible). I looked at the Is there any coding work (other than Tom Christie's branch) being done at this time ? If I could find some more example implementations, I'd be very pleased to test them. Sorry if this isn't the right place to ask those questions (I know that this issue is more about the DEP in itself). Also, maybe you should provide clear definitions (what goes in, what goes out, side effects if any) of what is a parser and a definition ? |
I think this is the right place for your comments. I couldn't find any other examples of currently on going work in this space. Of course the community has a number of solutions in:
With Tastypie and Rest Framework handle serializers which handle both incoming and outgoing types, the Piston Mimer is only meant for incoming requests and outgoing requests are handled by emitters. The serializers at times mix the parsing of incoming content types and the validation which I'm leaving out of the scope of this DEP. I'm going to continue to work on clarifying what exactly these APIs will be. I like Tom's general direction but I'd like to see a solution which doesn't include more settings. For most of the current solutions in the community these parsers are defined at the resource level. I wonder if that is largely due to the fact that they can't easily modify the parsing at global level or whether people believe it should be done on a per view/resource basis. |
I could be wrong, but REST Framework has parsers that are separate from serializers. The serializers basically function a little more like forms; parsers themselves handle raw input and convert into standard Python datatypes. |
Yes that's the same approach which is being described here. |
Actually to be clear the input-side validations are out of the scope of this proposal. |
If I understand correctly, you're merely talking about sucking in the body of a request and converting it into some useful dictionary of Python datatypes/objects. Obviously JSON is the most common in current usage, but it could be YAML, XML, JUnit, CSV, plain text, whatever. Validation would still be handled by forms. Correct? Would it also be worthwhile to make the API work in both directions? In other words, could a |
Correct. A JSON parser would be included with Django as part of this work. Additional parsers (YAML, XML, CSV) could be written and maintained as external projects. A description of how additional parsers would be registered is included in the proposal. Validations would be handled by forms or extensions of forms such as django-rest-frameworks serializers. This proposal does the response formatting as well. See the section on Reponse Types/Emitters https://github.com/django/deps/pull/1/files?short_path=76d7d47#response-types I don't see it being handled by the same parsing API functions/classes but that's more of an implementation detail. |
Hi @mlavin really great to see you getting this moving. The proposal looks good and all seems well-thought out. I'm a little unsure about the 'no settings' approach at the moment, as described it essentially just moves the parser configuration out of the My personal suggestion is that the way parsers are configured and set on the request should closely follow the You might also consider having the My main priority on any of this would be trying to ensure that REST framework (or a future release of it) nicely dovetails with any Django APIs - I think it'd be hugely beneficial for the community if we can make sure that the existing work that's been done on third party parsing and rendering can transition easily to being using directly with Django. Some quick points on this that I can follow up in more detail if needed.
I'm sure I'll have more to add as the proposal progresses, but looking really good! Thanks again. Tom |
Thanks for the feedback! I would say the motivations for not introducing another setting is two fold. One that feels like the general direction of Django in recent releases: trying to break dependencies on the settings as global state. Two there aren't good patterns for extending settings while keeping the defaults. There are a few in the community but none that I can find documented by Django itself. This gives users a foot-gun to do things like remove the form-encoded parsers with something like
This comes up often in the case of To me the most ideal solution is to deprecate |
Those points are reasonable enough. I don't feel particularly strongly about the
Indeed, if you do go with the no-settings approach it'd make sense to take the same style with the file parsing configuration. Though I'm not sure it follows that subclassing |
Yes it's more a matter of taste. That is should the |
We are trying to get the DEP process started again. Could you squash the commits into one? After that we can merge the proposal to drafts. |
Yes I'll incorporate some of the above feedback that I haven't yet addressed and squash my commits. |
Rename content-negotiation.txt to content-negotiation.rst Update copyright. More detail on the request parsing API. More detail on the response handling API. Minor tweaks to the DEP.
8a6e2fb
to
f5be41d
Compare
@akaariai the commits have been squashed. |
Content Negotiation Improvement draft DEP
This is a rough draft of a proposal for improving Django's support for content negotiation based on previous discussions on django-developers and work by @tomchristie. Currently it's fairly light on technical details but this process is very new and I'm not sure how much as needed at this point. Mostly I just want to revive this discussion and iterate on the details if it is agreed that this is something that would be an improvement to Django.