-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
📝 Clarify misleading "Required, can be None" section in query-params-str-validations.md
#14322
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
base: master
Are you sure you want to change the base?
📝 Clarify misleading "Required, can be None" section in query-params-str-validations.md
#14322
Conversation
|
Hi 👋, This is my first contribution to FastAPI 🎉 — really excited to start contributing to the project! |
📝 Docs previewLast commit 9f6fe4a at: https://774bf08f.fastapitiangolo.pages.dev Modified Pages |
None" section in query-params-str-validations.md
18ccbd1 to
f873cb9
Compare
This comment was marked as resolved.
This comment was marked as resolved.
9021a4b to
3259949
Compare
This comment was marked as resolved.
This comment was marked as resolved.
5a446c9 to
bb64c97
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
tests/test_tutorial/test_query_params_str_validations/test_tutorial006d_an_py310.py
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
YuriiMotov
left a comment
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.
LGTM!
@ChaitanyaSai-Meka, thanks!
|
Thanks @YuriiMotov! Really appreciate your review and guidance 🙌 |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
… can be None section
03ca4c1 to
1a4cdb3
Compare
This comment was marked as resolved.
This comment was marked as resolved.
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.
Pull request overview
This pull request clarifies misleading documentation about using "required" query parameters that can accept None values. The previous documentation incorrectly suggested that FastAPI could handle a truly required parameter that also accepts a real None value, but HTTP query parameters are always transmitted as strings, making this impossible.
Key Changes:
- Updated documentation to explain that HTTP query parameters cannot send real
Nonevalues - Added example demonstrating how to manually interpret string values like
"None"or empty strings asNoneusing Pydantic'sBeforeValidator - Removed old non-annotated example files and updated tests to match the new validator-based approach
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/en/docs/tutorial/query-params-str-validations.md | Rewrote "Required, can be None" section to clarify HTTP limitations and show validator workaround |
| docs_src/query_params_str_validations/tutorial006c_py39.py | Deleted - replaced with annotated version using BeforeValidator |
| docs_src/query_params_str_validations/tutorial006c_py310.py | Deleted - replaced with annotated version using BeforeValidator |
| docs_src/query_params_str_validations/tutorial006c_an_py39.py | Added nullable_str validator function and BeforeValidator to handle None-like strings |
| docs_src/query_params_str_validations/tutorial006c_an_py310.py | Added nullable_str validator function and BeforeValidator to handle None-like strings |
| tests/test_tutorial/test_query_params_str_validations/test_tutorial006c.py | Removed references to deleted files, updated tests to verify 422 on missing param and 200 on None-like strings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The previous explanation suggested that a query parameter could be both required and accept a true
Nonevalue.However, since HTTP query parameters are transmitted as strings, clients cannot actually send
Noneornull.This update clarifies that behavior and adds an example showing how to manually handle
"None"or empty strings asNoneinside a route.