[FEATURE] Support repeated key=value in form data
See original GitHub issueIs your feature request related to a problem
Yes.
Given some URL encoded data like this…
choices=parrot&choices=spider
…only the last key=value wins.
This does not work like I expected:
choices: list = Form(...)
You can only validate against the last value.
The solution you would like
Perhaps FastAPI should collect repeated keys in the 2-tuple list that request.form()
gives and assign those values as a list to the same key before validation happens.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
FormData.entries() - Web APIs | MDN
The FormData.entries() method returns an iterator which iterates through all key/value pairs contained in the FormData .
Read more >How to get multiple key values pair under array of object ...
How to get multiple key values pair under array of object through form data submition · You can do something like . var...
Read more >How can I send a list of records (multiple forms with key-value ...
How can I send a list of records (multiple forms with key-value pairs) in a single request via multipart/form-data HTTP POST.
Read more >FormData - The Modern JavaScript Tutorial
FormData objects can help with that. As you might have guessed, it's the object to represent HTML form data. The constructor is:.
Read more >Prevent duplicate values in a table field using an index
Set the field's Indexed property to Yes (No duplicates) You can do this by opening the table in Design view. · Create a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we still have an issue with
Form
andList
. When passing a list of elements as aForm
field, it doesn’t get parsed correctly:test1 example
test2 example
we can see how
Query
correctly parses the list, whereasForm
doesn’t. ChangingList[str]
tolist
doesn’t fix the problem. Accepting list of numbers withList[int]
for example returns an error as shown below, indicating thattyping.List
isn’t handled as expectedtest3 example
The curl commands have been copy pasted from the swagger web interface but I don’t see any change when running them from terminal. Using
fastapi==0.65.2
Thanks @StephenCarboni for the report 🔍 🕵️♂️
Thanks @nsidnev for the fix! 🎉 🚀
And thanks everyone here for the discussion.
The fix is available in the latest release.