-
-
Notifications
You must be signed in to change notification settings - Fork 228
_get_kwargs does not produce correct payload when there are data and files present #508
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
Comments
Thanks for reporting! I'm going to do a sweep of PRs and bugs this weekend so I'll try and get this one in too. |
For me this issue is still present in version 0.10.5. Instead of producing something like this:
I receive this output instead:
|
Looks like this was broken in 0.10.0 with #372. That was a really big PR, I should have done more testing on it 😞. Of course I don't want to break the feature that was added either. Sounds like in order to fix this properly is going to require really overhauling how multipart/form works (which will require me spending a bunch of time learning about it). If anyone else is really familiar with multipart/form and wants to take a crack at righting the various wrongs in this client, I'd be really happy to see another PR on this. Otherwise, it might be a bit before I can spend enough time to really get this right. |
I wonder if the explanation of the issue is linked to the fact that with httpx version 0.19.0 a breaking change was made that forces file upload content to be bytes type and won't accept str type anymore. So my suggestion would be to replace everywhere in templates the tuples
For example in enum_property.py.jinja
In list_property.py.jinja
And in
What do you think? |
FYI I did this modification in my custom templates directory and it works well with httpx > 0.20 |
Great find @kairntech! I confirmed that using the non-bytes variant (so as-generated today) in http 0.18.* works just fine, but I get the type error in the latest 0.21.1. I then added that little I'll whip up a patch with those changes and get them in, but for all interested before the new release gets out, you can work around this by using httpx < 0.19.0 |
Unfortunately I think the fix is going to be a breaking change, because I believe that the payload of a file can now only be |
Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
I've got a fix over in #548 which I've tested locally with some simple cases (though CI is annoyingly failing for everything right now). I'd really appreciate it if some of you could take a look, test it out with your own clients, and give it a review. It is a breaking change, so it'll wait until I'm ready to ship 0.11.0. Again, folks can work around this issue for now by using an older version of |
Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
…1-ilmn & @kairntech! Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
…1-ilmn & @kairntech! Fixes #508 BREAKING CHANGE: `File` uploads can now only accept binary payloads (`BinaryIO`).
Describe the bug
When an API endpoint accepts data and files as a part of a multipart form data, the generated code puts the
data
fields (expected byhttpx
) intofiles
, which leads to aTypeError
in httpx when trying to encode the multipart form data.To Reproduce
Steps to reproduce the behavior:
Expected behavior
Should not encounter
TypeError
inhttpx
. More specifically, the_get_kwargs()
function of the module for the endpoint needs to return an additional field,data
, in addition tofiles
for the plain text fields. That probably meansmultipart_data.to_multipart()
should return bothdata
andfiles
. Currently, it only returnsfiles
.OpenAPI Spec File
The openapi.yaml is private, but I can do my best to produce a snippet that would reproduce the error. The actual endpoint shouldn't matter because the
TypeError
is encountered before sending any requests.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: