← pod_r5_v1i

fastapi_14791

resolved RESOLVED PASS · 7 tool calls · 51 s · fastapi/fastapi

Task input

🐛 Update `ValidationError` schema to include `input` and `ctx`

## Summary

Related to #10787

The OpenAPI `ValidationError` schema was outdated and didn't reflect the actual error format returned by Pydantic V2.

## Changes
Updated `validation_error_definition` in `fastapi/openapi/utils.py` to include:
- `input`: The actual input value that caused the validation error  
- `ctx`: Optional context dictionary with additional error information

## Testing
All existing tests pass with the updated schema. The test snapshots have been updated to reflect the new schema structure.

Tool calls (8)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn 'validation_error_definition' fastapi/openapi/utils.py"
}
{"status": "ok", "stdout": "fastapi/openapi/utils.py:41:validation_error_definition = {\nfastapi/openapi/utils.py:435: \"ValidationError\": validation_error_def
full
{"status": "ok", "stdout": "fastapi/openapi/utils.py:41:validation_error_definition = {\nfastapi/openapi/utils.py:435:                            \"ValidationError\": validation_error_definition,\n", "stderr": "", "exit_code": 0}
2run_command
{
 "command": "sed -n '41,60p' fastapi/openapi/utils.py"
}
{"status": "ok", "stdout": "validation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title
full
{"status": "ok", "stdout": "validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n    \"title\": \"HTTPValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"detail\": {\n", "stderr": "", "exit_code": 0}
3run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/openapi/utils.py\")\ns = p.read_text()\nold = \"\"\"validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\nnew = \"\"\"validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n        \"input\": {\"title\": \"Input\", \"type\": \"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}, {\"type\": \"number\"}, {\"type\": \"boolean\"}, {\"type\": \"array\"}, {\"type\": \"object\"}]},\n        \"ctx\": {\"title\": \"Context\", \"type\": \"object\", \"nullable\": True},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\n# The above \"anyOf\" for input is slightly wrong in syntax, let me fix it.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
4run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/openapi/utils.py\")\ns = p.read_text()\nold = \"\"\"validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\nnew = \"\"\"validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n        \"input\": {\"title\": \"Input\"},\n        \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\n# In OpenAPI 3.0, if you don't specify \"type\", it can be anything.\n# Pydantic's \"input\" can be anything.\n# \"ctx\" is a dict (object).\nassert s.count(old) == 1\nt = s.replace(old, new)\np.write_text(t)\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
5run_command
{
 "command": "sed -n '41,60p' fastapi/openapi/utils.py"
}
{"status": "ok", "stdout": "validation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title
full
{"status": "ok", "stdout": "validation_error_definition = {\n    \"title\": \"ValidationError\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"loc\": {\n            \"title\": \"Location\",\n            \"type\": \"array\",\n            \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n        },\n        \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n        \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n        \"input\": {\"title\": \"Input\"},\n        \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n    },\n    \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n    \"title\": \"HTTPValidationError\",\n    \"type\": \"object\",\n", "stderr": "", "exit_code": 0}
6run_command
{
 "command": "git diff"
}
{"status": "ok", "stdout": "diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py\nindex 75ff2610..29f03bd2 100644\n--- a/fastapi/openapi/utils.py\n+
full
{"status": "ok", "stdout": "diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py\nindex 75ff2610..29f03bd2 100644\n--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -49,6 +49,8 @@ validation_error_definition = {\n         },\n         \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n         \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n+        \"input\": {\"title\": \"Input\"},\n+        \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n     },\n     \"required\": [\"loc\", \"msg\", \"type\"],\n }\n", "stderr": "", "exit_code": 0}
7run_command
{
 "command": "submit_patch"
}
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/bas
full
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/bash: submit_patch: command not found\n", "exit_code": 127}}
8submit_patch
{}
{"status": "ok", "patch_size": 483, "files_changed": 1}
full
{"status": "ok", "patch_size": 483, "files_changed": 1}

Patch

diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index 75ff2610..29f03bd2 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -49,6 +49,8 @@ validation_error_definition = {
         },
         "msg": {"title": "Message", "type": "string"},
         "type": {"title": "Error Type", "type": "string"},
+        "input": {"title": "Input"},
+        "ctx": {"title": "Context", "type": "object"},
     },
     "required": ["loc", "msg", "type"],
 }

Test output

show
........................................................................ [ 43%]
........................................................................ [ 87%]
.....................                                                    [100%]
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
  /Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
165 passed, 1 warning in 1.71s