failed WRONG_FIX wrong_fix · 6 tool calls · 118 s · fastapi/fastapi
🐛 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 | Arguments | Result |
|---|---|---|---|
| 1 | run_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_deffull{"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} |
| 2 | run_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 \"titlefull{"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} |
| 3 | run_command | {
"command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/openapi/utils.py\"); s = 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\": \"array\"}, {\"type\": \"object\"}]},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\", \"nullable\": True},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\n# Wait, \"anyOf\" is not a valid \"type\" value in JSON Schema. It should be a sibling of \"type\" or replace it.\n# Let's check how \"loc\" items are defined: \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]}\n# So for \"input\", it should be \"input\": {\"title\": \"Input\", \"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}, {\"type\": \"array\"}, {\"type\": \"object\"}]}\n# Actually, in OpenAPI 3.0, \"anyOf\" is a top-level property of the schema object.\nPY\n"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 4 | run_command | {
"command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/openapi/utils.py\"); s = 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\", \"nullable\": True},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\"\"\"\nassert s.count(old) == 1, (\"old text found this many times:\", s.count(old))\nt = s.replace(old, new); compile(t, str(p), \"exec\"); p.write_text(t)\nPY\n"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 5 | run_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 \"titlefull{"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\", \"nullable\": True},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n \"title\": \"HTTPValidationError\",\n \"type\": \"object\",\n", "stderr": "", "exit_code": 0} |
| 6 | run_command | {
"command": "git diff"
} | {"status": "ok", "stdout": "diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py\nindex 75ff2610..93109bdc 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..93109bdc 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\", \"nullable\": True},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n }\n", "stderr": "", "exit_code": 0} |
| 7 | submit_patch | {} | {"status": "ok", "patch_size": 501, "files_changed": 1}full{"status": "ok", "patch_size": 501, "files_changed": 1} |
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index 75ff2610..93109bdc 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", "nullable": True},
},
"required": ["loc", "msg", "type"],
}
.F
=================================== FAILURES ===================================
_____________________________ test_openapi_schema ______________________________
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
> assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/foo": {
"post": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
"summary": "Foo",
"operationId": "foo_foo_post",
"requestBody": {
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Items"}
}
},
"required": True,
},
}
}
},
"components": {
"schemas": {
"Items": {
"title": "Items",
"required": ["items"],
"type": "object",
"properties": {
"items": {
"title": "Items",
"type": "object",
"additionalProperties": {"type": "integer"},
}
},
},
"ValidationError": {
"title": "ValidationError",
"required": ["loc", "msg", "type"],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [{"type": "string"}, {"type": "integer"}]
},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
"input": {"title": "Input"},
"ctx": {"title": "Context", "type": "object"},
},
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"},
}
},
},
}
},
}
E AssertionError: assert {'openapi': '...tionError'}}}} == {'openapi': '...': {...}}}}}}}
E
E Omitting 3 identical items, use -vv to show
E Differing items:
E {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'type': 'array', 'title'...'input': {'title': 'Input'}, ...}, 'type': 'object', 'required': ['loc', 'msg', 'type'], 'title': 'ValidationError'}}}} != {'components': {'schemas': {'Items': {'title': 'Items', 'required': ['items'], 'type': 'object', 'properties': {'items...PValidationError', 'type': 'object', 'properties': {'detail': {'title': 'Detail', 'type': 'array', 'items': {...}}}}}}}
E Use -v to get more diff
tests/test_additional_properties.py:29: AssertionError
=============================== 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
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 1 passed, 1 warning in 0.90s