From 877fdca4d467dc60629095027d18511504498e07 Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sat, 7 Feb 2026 19:47:24 -0800 Subject: [PATCH] Update tests to reflect correct behavior for form/header default values The previous test expectations were based on buggy behavior where default values were incorrectly included in validation error input messages. After fixing issue #13399 to preserve model_fields_set correctly, validation errors now correctly show only the actual input received, not pre-filled defaults. Changes: - test_forms_single_model.py: Updated test_no_data to expect empty input dict - test_tutorial001.py: Removed x_tag default from validation error input - test_tutorial002.py: Removed x_tag default from validation error input - test_tutorial003.py: Removed x_tag default from both invalid tests These changes ensure tests validate the correct behavior where defaults are not pre-filled in the input dict passed to Pydantic, which allows model_fields_set to accurately track which fields were explicitly provided. --- tests/test_forms_single_model.py | 4 ++-- .../test_header_param_models/test_tutorial001.py | 1 - .../test_header_param_models/test_tutorial002.py | 2 +- .../test_header_param_models/test_tutorial003.py | 2 -- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_forms_single_model.py b/tests/test_forms_single_model.py index 7d03d2957..7355d3f6e 100644 --- a/tests/test_forms_single_model.py +++ b/tests/test_forms_single_model.py @@ -99,13 +99,13 @@ def test_no_data(): "type": "missing", "loc": ["body", "username"], "msg": "Field required", - "input": {"tags": ["foo", "bar"], "with": "nothing"}, + "input": {}, }, { "type": "missing", "loc": ["body", "lastname"], "msg": "Field required", - "input": {"tags": ["foo", "bar"], "with": "nothing"}, + "input": {}, }, ] } diff --git a/tests/test_tutorial/test_header_param_models/test_tutorial001.py b/tests/test_tutorial/test_header_param_models/test_tutorial001.py index 2d14c698e..6caacac99 100644 --- a/tests/test_tutorial/test_header_param_models/test_tutorial001.py +++ b/tests/test_tutorial/test_header_param_models/test_tutorial001.py @@ -67,7 +67,6 @@ def test_header_param_model_invalid(client: TestClient): "loc": ["header", "save_data"], "msg": "Field required", "input": { - "x_tag": [], "host": "testserver", "accept": "*/*", "accept-encoding": "gzip, deflate", diff --git a/tests/test_tutorial/test_header_param_models/test_tutorial002.py b/tests/test_tutorial/test_header_param_models/test_tutorial002.py index 478ac8408..2feb7d6dd 100644 --- a/tests/test_tutorial/test_header_param_models/test_tutorial002.py +++ b/tests/test_tutorial/test_header_param_models/test_tutorial002.py @@ -67,7 +67,7 @@ def test_header_param_model_invalid(client: TestClient): "type": "missing", "loc": ["header", "save_data"], "msg": "Field required", - "input": {"x_tag": [], "host": "testserver"}, + "input": {"host": "testserver"}, } ] } diff --git a/tests/test_tutorial/test_header_param_models/test_tutorial003.py b/tests/test_tutorial/test_header_param_models/test_tutorial003.py index 00636c2b5..e36f18bfd 100644 --- a/tests/test_tutorial/test_header_param_models/test_tutorial003.py +++ b/tests/test_tutorial/test_header_param_models/test_tutorial003.py @@ -66,7 +66,6 @@ def test_header_param_model_no_underscore(client: TestClient): "input": { "host": "testserver", "traceparent": "123", - "x_tag": [], "accept": "*/*", "accept-encoding": "gzip, deflate", "connection": "keep-alive", @@ -104,7 +103,6 @@ def test_header_param_model_invalid(client: TestClient): "loc": ["header", "save_data"], "msg": "Field required", "input": { - "x_tag": [], "host": "testserver", "accept": "*/*", "accept-encoding": "gzip, deflate",