[Feature] Allow empty Form fields
See original GitHub issueI see that FastAPI does support Form data input. However it does not seem to support empty form fields and throws error:
{"detail":[{"loc":["body","searchstr"],"msg":"field required","type":"value_error.missing"}]}
Basically, fastapi expects all fields that are going to be handled should not be empty, which is not realistic IMHO. Or can someone show me a workaround?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
allow-empty-form-fields - IBM
If a forms login request is received with either an empty user name or an empty password, then WebSEAL returns the login form...
Read more >Solved: Allow empty Description (linked field) in Forms
When creating the new Forms request type. I've noticed that if i create my own input field, i can link them to the...
Read more >How to allow a form to submit, but prevent blank fields from ...
The problem I am running into is, whenever I create an instance of Item using the Admin form and I do not provide...
Read more >JavaScript : HTML form - Checking for non empty - w3resource
Javascript function to check if a field in a html form is empty or not.
Read more >How To Add Validation For Empty Input Field with JavaScript
JavaScript validation for empty input field. Try to submit the form without entering any text. Name: Step 1) Add HTML: ...
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
@borako
FastAPI
uses thepydantic
’s convention to mark fields as required. As described here, if you use...
in the definition of a query parameter, thenFastAPI
will require this field in the request input. The same is true for theForm
,Body
and other parameters fromFastAPI
. You can set a default value for your field if it can be omitted in the form data. Additionally, you can mark the field astyping.Optional
if you don’t want a static analyzer likemypy
to complain about types. Here is an example:There are 3 form fields defined for this endpoint, but
FastAPI
will require that onlymy_required_field
be present in the user input. Here are some examples of requests to this application using thehttpie
client:This is great, very helpful. I understand fastapi borrows a lot of pieces from others (starlette, pydantic, etc.). Being not familiar with those technologies, fastapi user guide sections for Form data look too simplistic. It’ll be wonderful if this makes into those sections in the future. Thanks! Bora