diff --git a/fastapi/error_handlers.py b/fastapi/error_handlers.py index 192ef4064..52a32119a 100644 --- a/fastapi/error_handlers.py +++ b/fastapi/error_handlers.py @@ -29,7 +29,10 @@ def convert_exception_to_status_body(exc: Exception) -> tuple[int, dict]: status_code = exc.status_code details = exc.detail elif isinstance(exc, RequestValidationError): - status_code = status.HTTP_422_UNPROCESSABLE_CONTENT + # Use integer status code to supress starlette >= 0.48 deprecation warning + # See: https://github.com/fastapi/fastapi/pull/14077 + # status_code = status.HTTP_422_UNPROCESSABLE_CONTENT + status_code = 422 details = jsonable_encoder(exc.errors()) elif isinstance(exc, WebSocketRequestValidationError): status_code = status.WS_1008_POLICY_VIOLATION diff --git a/fastapi/tests/test_fastapi.py b/fastapi/tests/test_fastapi.py index c9eae09b8..35fa7ac99 100644 --- a/fastapi/tests/test_fastapi.py +++ b/fastapi/tests/test_fastapi.py @@ -156,9 +156,7 @@ def test_request_validation_error(self) -> None: route = "/fastapi_demo/demo/exception?exception_type=BAD&error_message=" response = self.url_open(route, timeout=200) mocked_commit.assert_not_called() - self.assertEqual( - response.status_code, status.HTTP_422_UNPROCESSABLE_CONTENT - ) + self.assertEqual(response.status_code, 422) def test_no_commit_on_exception(self) -> None: # this test check that the way we mock the cursor is working as expected