-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(python,asyncio): multipart form data serialization #19302
fix(python,asyncio): multipart form data serialization #19302
Conversation
f2a8321
to
29b4a60
Compare
|
29b4a60
to
6351aa8
Compare
@wing328 following up - are you the right person to review this? |
@cbornet @tomplus @krjakbrjak @fa0311 @multani I'd really appreciate your review, thank you! |
@roryschadler sorry for the delay ; would you be able to extend the test suite to show the bug and your change fixes it? |
This PR is essentially <OpenAPITools#18140> but for the asyncio client.
urllib3 handles serializing ints in post params (ref 1), while asyncio explicitly does not (ref 2). ref 1: <https://github.com/urllib3/urllib3/blob/9316764e90aea8d193cd8f03b0caccdf02af3ba0/src/urllib3/filepost.py#L75-L76> ref 2: <aio-libs/aiohttp#920>
No worries @multani! Happy to. Just to confirm, is that a manually-written test added to https://github.com/OpenAPITools/openapi-generator/tree/0f294a51297d788630c96a146a9a48d1dae3e3e5/samples/openapi3/client/petstore/python/tests, or do you mean a different test suite? |
Yes, this folder would be a good place. The test file you already updated should contain some serialization tests already, maybe it could be a good place to extend with a regression test for your fix! |
6351aa8
to
edd933a
Compare
@roryschadler thanks for the tests, I will take a look. In the meantime, can you regenerate the sample files using the commands in the first message of the PR and commit the result? It should fix the unsuccessful check. Thanks! |
I did a basic check if the fix was working and it seems so. I'm really not familiar with the multipart code, @wing328 if you want to take another look, that would be great :) |
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.
Can you adjust the aiohttp test setup? It took me some time to figure out why it wasn't working on my machine :)
The same fix should probably be done for pydantic-v1-aiohttp.
samples/openapi3/client/petstore/python-aiohttp/tests/test_rest.py
Outdated
Show resolved
Hide resolved
Extends previous commits (and OpenAPITools#18140) to cover the python-pydantic-v1 client as well.
Also brings the second test in line with the first, patching `urllib3.PoolManager.urlopen`
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.
Looks good to me, thanks for the fix(es) @roryschadler !
@wing328 can you take a look as well?
@wing328 bumping this up in your inbox. Looking forward to your review, thank you! |
@wing328 Checking in on this. Is there anything I can do to support your review? |
thanks for the PR, which has been merged sorry for the delay. |
Thank you, @wing328! |
This PR tackles a few serialization issues in the Python generator templates: serialization of dictionaries and integers in
multipart/form-data
requests.I generated a
library=asyncio
client using latestmaster
andmodules/openapi-generator/src/test/resources/3_0/form-multipart-binary-array.yaml
. The/multipart-mixed
call fails withTypeError: Can not serialize value type: <class 'dict'>
.#18140 resolved this for
library=urllib
clients, but not forlibrary=asyncio
clients. Becausetornado
clients are deprecated, I didn't try to reproduce the bug there.With that client created and installed, this snippet demonstrates the
dict
issues onmaster
, and the fix here:The other issue is serializing integers, which is also broken for
library=asyncio
clients. If a spec lists amultipart/form-data
field as a number, then it needs to be stringified before being written to the form body.aiohttp
has stated they won't do this for the user: aio-libs/aiohttp#920.urllib3
handles this for the user here: https://github.com/urllib3/urllib3/blob/9316764e90aea8d193cd8f03b0caccdf02af3ba0/src/urllib3/filepost.py#L75-L76PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)