-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
Fix for discarded form data #954
Conversation
@@ -273,6 +273,9 @@ def _get_body_argument(self, body, arguments, has_kwargs, sanitize): | |||
|
|||
if x_body_name in arguments or has_kwargs: | |||
return {x_body_name: res} | |||
# If the content type is "multipart/form-data" return the properties as-is | |||
if self.consumes[0] == 'multipart/form-data': | |||
return res | |||
return {} |
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.
I am pretty sure it might be sufficient to just return res
in here.
In method that calls the one you modified, request.form.items
is put into request_body
.
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.
Also, that's is needed for #987 to work.
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.
I just did it like this because I wasn't entirely sure if a non-empty response was always going to be the correct response. I can most certainly change it though.
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.
I pulled that version into #987 and there are some tests failing, so yours might be better TBH.
Rebase on top of master BTW, there are some changes that should make it better with tests and for you to see if direction is fine.
connexion/operations/openapi.py
Outdated
@@ -273,6 +273,9 @@ def _get_body_argument(self, body, arguments, has_kwargs, sanitize): | |||
|
|||
if x_body_name in arguments or has_kwargs: | |||
return {x_body_name: res} | |||
# If the content type is "multipart/form-data" return the properties as-is | |||
if self.consumes[0] == 'multipart/form-data': |
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.
I believe it might be better to use this code. connexion
maintains own list of what it understands as multipart.
if self.consumes[0] == 'multipart/form-data': | |
from .. import http_facts | |
if self.consumes[0] in http_facts.FORM_CONTENT_TYPES: |
PS. I am not sure if amounts of dots is OK, but there is for sure a module http_facts
in root package.
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.
Ah, that's definitely better than mine :-)
…questBody has no name
9341956
to
2f2bed0
Compare
Why was this pull request closed? It doesn't appear to merged into master/main ever, yet it was a fix for an issue I'm facing with multipart form data. |
Attempt to fix a situation where form data is thrown away when the requestBody has no name.
This PR fixes a problem I'm having where a POST requestBody without a name is being discarded. I'm not sure if this is the correct way to do it, but this solves my problem. Please let me know if you know of a better way of doing this.
See issue #935 for more information about this.
Changes proposed in this pull request: