-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Form-encoded data with None as the value gets passed as string "None" #8052
Comments
This seems like an antipattern to me and I'd be more inclined to raise a TypeError. I don't have a strong opinion though, so if other maintainers think it's a good idea then I'm fine with it. I would note there is a lack of type annotations here though, so those should probably be fixed regardless ( |
Some easy workaround i found is on stackoverflow, just remove dict element with None value. Code snapshot {k: v for k, v in data.items() if v is not None} |
Yes, exactly. If you don't want a parameter output, then don't pass a parameter at all. Passing |
I would like to know if this behavior is documented and is it already included in test? If not, i suggest provide the documentation and add the test for this behavior, so the expected behavior is defined, which result as None string. |
Is that the expected behaviour though? As far as I can tell the method expects string values. Any other type should either raise a TypeError or, to save some performance, have undefined behaviour. |
Honestly, response with string |
Again, I'd learn towards a TypeError. It suggests the developer has done something wrong in their code. If you'd like to contribute such a change, I'm happy to review. Most importantly, we need the type annotations sorted as mentioned in my initial comment. Then atleast type checkers will give an error when a developer has a None. |
Describe the bug
When i have form encoded data with
None
, by using requests the data is not sent to the server. But this is different for aiohttp, is sent"None"
string. This happen also in httpx, take a look at this issue encode/httpx#1500. Is this really the expected behavior?To Reproduce
Code
Output
Take a look at the
form
, its contain None'form': {'foo': 'None'}
.Expected behavior
Code
Output
Take a look at the
form
, its empty'form': {}
.Logs/tracebacks
Python Version
Python 3.12.1
aiohttp Version
multidict Version
yarl Version
OS
Windows 10
Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: