Skip to content

Commit

Permalink
Merge pull request #1026 from lsst-sqre/tickets/DM-44269
Browse files Browse the repository at this point in the history
DM-44269: Remove workaround for FastAPI bug
  • Loading branch information
rra committed May 9, 2024
2 parents 6c1ab3d + 8abc13f commit bc935af
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/gafaelfawr/main.py
Expand Up @@ -9,12 +9,8 @@
from pathlib import Path

import structlog
from fastapi import FastAPI, Request, status
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic_core import PydanticUndefinedType
from safir.dependencies.db_session import db_session_dependency
from safir.dependencies.http_client import http_client_dependency
from safir.fastapi import ClientRequestError, client_request_error_handler
Expand Down Expand Up @@ -185,26 +181,4 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
# Handle exceptions descended from ClientRequestError.
app.exception_handler(ClientRequestError)(client_request_error_handler)

# This is a temporary workaround for a bug in FastAPI handling Pydantic
# validation errors when a list query parameter is not specified. See
# https://github.com/tiangolo/fastapi/issues/9920
#
# This should be removed when that issue is fixed.
@app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(
request: Request, exc: RequestValidationError
) -> JSONResponse:
"""Handle request validation errors."""
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content={
"detail": jsonable_encoder(
exc.errors(),
custom_encoder={
PydanticUndefinedType: lambda _: None,
},
)
},
)

return app

0 comments on commit bc935af

Please sign in to comment.