Skip to content

Ignore many=True serializer on POST during html form rendering #3138

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

Closed
wants to merge 1 commit into from
Closed

Ignore many=True serializer on POST during html form rendering #3138

wants to merge 1 commit into from

Conversation

asedeno
Copy link

@asedeno asedeno commented Jul 10, 2015

I've been fighting issue #2918 all afternoon. After finding the (closed!) issue, I started poking at the rest framework code for a simple work-around.

I don't know if this is correct, though it does get me past my problems. This makes get_rendered_html_form ignore the serializer on hand for POST if many=True, and rediscovers what the serializer should be.

Existing tests still pass. Comments welcome.

@tomchristie
Copy link
Member

Going to stay with the assessment here... #2918 (comment)

If this or a similar pull request came with a convincing case of what the behavioral change would be and why it's the right thing to do, then could reconsider.

@asedeno
Copy link
Author

asedeno commented Jul 13, 2015

My use case is a complicated search query where we want to POST the search criteria and return a serialized list of results. The request works just fine until you try to use the browsable API, in which case it crashes rendering the form, having already generated the correct search results.

I'm not sure what else you are looking for. All I'm trying to do is get a use case to not raise exceptions when the correct behavior is possible. The behavioral change here to dynamically generate a serializer in the case that we believe trying to use the existing serializer will raise.

@tomchristie
Copy link
Member

I'm not sure what else you are looking for.

I appreciate that this change meets your particular use case, but it'll also negatively impact the browsable API for folks in other situations (by not including the form input).

Show me a more reasoned "this is what it changes, this is the set of cases it'd fix, this is why we're only doing this for POST" and we might be able to consider it valid, but right now it's just special casing 'POST' and it's not at all clear if or why this'd be the right thing to do.

@asedeno
Copy link
Author

asedeno commented Jul 13, 2015

So right now the exception being thrown is:
TypeError: 'ListSerializer' object is not iterable

How would you feel if instead of special-casing POST with many=True, I caught the TypeError on rendering the form and retried with a dynamically generated serializer. In that case, I'm only affecting broken cases.

@asedeno
Copy link
Author

asedeno commented Jul 13, 2015

Such a commit now exists on the many-post branch I was trying to merge.

@tomchristie
Copy link
Member

That might be okay. No promises, but best thing to do would be to write the smallest possible test case that replicates the issue. Can you do so against a regular view, or does it need to be a viewset with a custom route added? At that point we'll have enough info to make a better judgement on this, and either:

  • get the behavior right first time.
  • catch and gracefully fallback on error.
  • note that it's a case that can't be automatically handled and document it as a constraint, explaining how to work around.

@asedeno
Copy link
Author

asedeno commented Jul 13, 2015

I have a test case for you now; I'm not sure it's the smallest possible test case, but it's pretty small.
https://github.com/asedeno/django-rest-framework/commit/3ef9c81949237aae655f050c14e81a3a9105f6f5

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy