Traceback (most recent call last):
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__
raise e
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__
await self.app(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\routing.py", line 718, in __call__
await route.handle(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\routing.py", line 66, in app
response = await func(request)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\routing.py", line 271, in app
raise RequestValidationError(_normalize_errors(errors), body=body)
fastapi.exceptions.RequestValidationError: [{'type': 'list_type', 'loc': ('query', 'device_ids'), 'msg': 'Input should be a valid list', 'input': PydanticUndefined, 'url': 'https://errors.pydantic.dev/2.0.3/v/list_type'}]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\encoders.py", line 230, in jsonable_encoder
data = dict(obj)
TypeError: 'pydantic_core._pydantic_core.PydanticUndefinedType' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\encoders.py", line 235, in jsonable_encoder
data = vars(obj)
TypeError: vars() argument must have __dict__ attribute
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 426, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\applications.py", line 289, in __call__
await super().__call__(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\applications.py", line 122, in __call__
await self.middleware_stack(scope, receive, send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
raise exc
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\starlette\middleware\exceptions.py", line 88, in __call__
response = await handler(request, exc)
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\exception_handlers.py", line 26, in request_validation_exception_handler
content={"detail": jsonable_encoder(exc.errors())},
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\encoders.py", line 209, in jsonable_encoder
jsonable_encoder(
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\encoders.py", line 195, in jsonable_encoder
encoded_value = jsonable_encoder(
File "C:\Users\Ivan\workspace\redacted\.venv\lib\site-packages\fastapi\encoders.py", line 238, in jsonable_encoder
raise ValueError(errors) from e
ValueError: [TypeError("'pydantic_core._pydantic_core.PydanticUndefinedType' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
Privileged issue
Issue Content
Although I have not contacted tiangolo, I received an approval from @Kludex to create an issue for this.
Right now there is a problem with how FastAPI handles
RequestValidationErrorwhen alistquery parameter is empty with Pydantic v2. Quoting Kludex's original comment:To provide some context, when the
RequestValidationErroris raised, the default handler tries to serialise the error withjsonable_encoder, which calls eitherdictorvars.https://github.com/tiangolo/fastapi/blob/f7e3559bd5997f831fb9b02bef9c767a50facbc3/fastapi/exception_handlers.py#L20-L26
https://github.com/tiangolo/fastapi/blob/f7e3559bd5997f831fb9b02bef9c767a50facbc3/fastapi/encoders.py#L229-L238
However, when a
listquery parameter is empty, Pydantic somehow returns aPydanticUndefinedTypethatjsonable_encodercannot understand, raising an uncaught exception (traceback from @ivankoster's original comment)