Skip to content

Conversation

@ChaitanyaSai-Meka
Copy link

The previous explanation suggested that a query parameter could be both required and accept a true None value.
However, since HTTP query parameters are transmitted as strings, clients cannot actually send None or null.

This update clarifies that behavior and adds an example showing how to manually handle "None" or empty strings as None inside a route.

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Nov 10, 2025
@ChaitanyaSai-Meka
Copy link
Author

Hi 👋,
This PR clarifies a small inaccuracy in the “Required, can be None” section of the Query Params tutorial.
It explains that query parameters can’t actually carry None and adds a short example showing how to handle special values like "None" or an empty string.

This is my first contribution to FastAPI 🎉 — really excited to start contributing to the project!

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

YuriiMotov

This comment was marked as resolved.

@YuriiMotov YuriiMotov changed the title Clarify misleading “Required, can be None” section in query parameter validation 📝 Clarify misleading "Required, can be None" section in query-params-str-validations.md Nov 10, 2025
@ChaitanyaSai-Meka ChaitanyaSai-Meka force-pushed the docs/fix-required-can-be-none branch from 18ccbd1 to f873cb9 Compare November 10, 2025 09:44
@ChaitanyaSai-Meka

This comment was marked as resolved.

YuriiMotov

This comment was marked as resolved.

@ChaitanyaSai-Meka ChaitanyaSai-Meka force-pushed the docs/fix-required-can-be-none branch 2 times, most recently from 9021a4b to 3259949 Compare November 10, 2025 10:00
@ChaitanyaSai-Meka

This comment was marked as resolved.

@ChaitanyaSai-Meka ChaitanyaSai-Meka force-pushed the docs/fix-required-can-be-none branch from 5a446c9 to bb64c97 Compare November 10, 2025 10:16
@ChaitanyaSai-Meka

This comment was marked as resolved.

@ChaitanyaSai-Meka

This comment was marked as resolved.

@ChaitanyaSai-Meka

This comment was marked as resolved.

@YuriiMotov

This comment was marked as resolved.

@ChaitanyaSai-Meka

This comment was marked as resolved.

Copy link
Member

@YuriiMotov YuriiMotov left a 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!

@ChaitanyaSai-Meka
Copy link
Author

Thanks @YuriiMotov! Really appreciate your review and guidance 🙌
Glad to have contributed to FastAPI!

@ChaitanyaSai-Meka

This comment was marked as resolved.

@YuriiMotov

This comment was marked as resolved.

@ChaitanyaSai-Meka

This comment was marked as resolved.

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 16, 2025
@github-actions

This comment was marked as resolved.

@YuriiMotov YuriiMotov linked an issue Dec 18, 2025 that may be closed by this pull request
9 tasks
Copilot AI review requested due to automatic review settings January 8, 2026 11:30
@YuriiMotov YuriiMotov force-pushed the docs/fix-required-can-be-none branch from 03ca4c1 to 1a4cdb3 Compare January 8, 2026 11:30
@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Jan 8, 2026
@codspeed-hq

This comment was marked as resolved.

Copy link

Copilot AI left a 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 None values
  • Added example demonstrating how to manually interpret string values like "None" or empty strings as None using Pydantic's BeforeValidator
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question about "Required, can be None" parameter

2 participants