Closed euri10 closed 1 year ago
whats the input you are sending?
whats the input you are sending?
the short version of the log above is that I'm entering 1 for both the input name
and input amount
in the form.
what is strange is that for url-encoded forms I get a 201 on all 3 endpoints, the data.name is a string as expected.
but as soon as you have multi-part forms, for the same inputs, the pydantic is the only one returning a 201, others return a 400 complaining data.name is not a string
if I take as an example the multipart vs url-encoded using the msgspec Struct only, by the time we reach this line: https://github.com/litestar-org/litestar/blob/c36dba249337062266fe2175a256ed7de099fa0e/litestar/_signature/model.py#L190
what we have when entering both times 1 and 1 in the browser.
{'request': <litestar.connection.request.Request object at 0x7f955cf165c0>, 'data': {'amount': '1', 'name': '1'}}
{'request': <litestar.connection.request.Request object at 0x7f955cf16fc0>, 'data': {'name': 1, 'amount': 1}}
Well, the difference between url-encoded and multipart is that for url encoded we parse the raw request to a dict of string/string key value pairs and then let msgspec, attrs, pydantic etc. to handle validation and parsing. For multipart we use regex, and I think it's probable we do some conversion there.
We might need to ensure everything remains a string as well.
from briefly looking at it, I think this might be due to this line in https://github.com/litestar-org/litestar/blob/c36dba249337062266fe2175a256ed7de099fa0e/litestar/_multipart.py#L160
if you replace it with fields[field_name].append(post_data.decode())
then a 201 occurs.
I think the decoding using msgspec is too early,
will try a PR with this and see how it afffects the tests :)
from briefly looking at it, I think this might be due to this line in https://github.com/litestar-org/litestar/blob/c36dba249337062266fe2175a256ed7de099fa0e/litestar/_multipart.py#L160
if you replace it with
fields[field_name].append(post_data.decode())
then a 201 occurs.I think the decoding using msgspec is too early,
will try a PR with this and see how it afffects the tests :)
Great 👍
Description
Given this little app that basically enables in a browser to post a form to 6 different routes: atrts/msgspec/pydantic times url-encoded/multi-part version, I have isues to understand why the multi-part pydantic vs attrs/msgspec different behaviour.
I would expect a 201 on all and get a 400 on multi-part msgspec and attrs (see logs), is that intended ?
Input I pass is purposedely 1 and 1 for name and amount and the same for all POST logs below.
URL to code causing the issue
No response
MCVE
Steps to reproduce
No response
Screenshots
Logs
Litestar Version
Platform
Funding