From 3f0f5ba1e35a8ce31d3c1efb36c0eee6516a4110 Mon Sep 17 00:00:00 2001 From: Shaan-alpha <146729792+Shaan-alpha@users.noreply.github.com> Date: Thu, 14 May 2026 00:44:56 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Clarify=20Required=20can=20be=20?= =?UTF-8?q?None=20for=20query=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/tutorial/query-params-str-validations.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/en/docs/tutorial/query-params-str-validations.md b/docs/en/docs/tutorial/query-params-str-validations.md index 4765b36cbe..5ddc34b1e6 100644 --- a/docs/en/docs/tutorial/query-params-str-validations.md +++ b/docs/en/docs/tutorial/query-params-str-validations.md @@ -224,6 +224,14 @@ So, when you need to declare a value as required while using `Query`, you can si You can declare that a parameter can accept `None`, but that it's still required. This would force clients to send a value, even if the value is `None`. +/// info + +Keep in mind that for **query parameters** specifically, since they are extracted from the URL as strings, it's not really possible to send a `None` value natively. If you omit the parameter from the URL, you will get an error saying it's required. If you send it empty like `?q=`, the value will be an empty string `""`, not `None`. + +This "required but can be None" pattern is much more useful and common when working with JSON data (request bodies) where you can explicitly send a `null` value. 🤓 + +/// + To do that, you can declare that `None` is a valid type but simply do not declare a default value: {* ../../docs_src/query_params_str_validations/tutorial006c_an_py310.py hl[9] *}