Repository navigation
Conversation
…/5xx ExceptionHandlers.exception read `error.errors` without calling it. For a pydantic ValidationError that is a bound method, not a list, so a required provider QueryParams field missing from the request fell through to "500 Unexpected Error -> ValidationError". It now calls errors(); only a missing QueryParams field is a 422, so a provider Data model failing on an upstream response that dropped a key stays a 500. The detail goes through jsonable_encoder, because the error input can hold dates. TimeoutError now maps to 504 and json.JSONDecodeError (an upstream that answered with HTML or an empty body) to 502, each with a clear detail. AppLoader registers both by type: the Exception catch-all runs outside the CORS middleware, so its responses carry no CORS headers and a browser sees a CORS failure instead of the status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t input Provider extensions name query models freely (e.g. BalanceQuery), so the title check alone left their missing inputs at 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dlee-bq
left a comment
There was a problem hiding this comment.
Hi @artcashin, thanks for the PR. This is good for the most part, but there's some handling needing further consideration:
- requests.Timeout isn’t a subclass of TimeoutError, and Nasdaq and others use requests, so those timeouts are still 500s.
- When amake_request gets a blocked page served as text/html, aiohttp raises ContentTypeError, not JSONDecodeError. That is probably the most common “non-JSON upstream” case, and it isn’t covered.
- Python 3.10: core declares >=3.10, but on 3.10 asyncio.TimeoutError is not the builtin TimeoutError. aiohttp timeouts would stay 500 there.
- The 422 body has a different shape: a single dict, with loc: ["code"] and pydantic’s url. FastAPI’s own 422s, and the existing validation path, return a list with loc: ["query", ...]. Clients that parse FastAPI-style 422s will see the difference, and only the first missing field is reported.
Do we need to register additional handling in the Python Interface's Exception Handlers?
… FastAPI-style 422 Review follow-up: - requests.Timeout (an OSError) and asyncio.TimeoutError (its own class on Python 3.10) map to 504 alongside the builtin TimeoutError. - aiohttp ContentTypeError, raised when a JSON response arrives as text/html, maps to 502 alongside JSONDecodeError. - A missing QueryParams field is handled by the existing validation path, so the 422 detail is a list with loc ["query", ...], without the pydantic url, and reports every missing field. The single-dict branch in `exception` is back to what develop has. - All of these types are registered by type, so they keep CORS headers. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thanks, @dlee-bq, and apologies for the slow turnaround. All four points are addressed in ea3edec.
Every one of these types is registered by type in Python interface. I don't think it needs anything. Not covered: Tests: the two files pass 35/35 on Python 3.12 and 3.10. |
Problem
ExceptionHandlers.exceptiongives REST clients the wrong status in three cases:QueryParamsfield is absent from the request,validationpasses theValidationErroron toexception. That handler readserror.errorswithout calling it. For a pydanticValidationErrorthat is a bound method, not a list, so its "missing" branch never runs and the client gets500 Unexpected Error -> ValidationError.Unexpected Error -> TimeoutError.json.JSONDecodeErroris aValueError, so it takes theValueErrorbranch and the client is told its own request was invalid, when the upstream sent HTML or an empty body.The
Exceptioncatch-all also runs in Starlette'sServerErrorMiddleware, outsideCORSMiddleware, so its responses carry no CORS headers. A browser client sees a CORS failure instead of the status.Change
validationalready answers a FastAPI-style 422 for aQueryParamserror whose fields are in the request's query. A missing field cannot be in the query, so it fell through toexception.validationnow leaves "missing" errors out of that check, so the body is the list it already returns:loc: ["query", "code"], nourl, every missing field reported. It also accepts anyQueryParamssubclass, whatever its name. A providerDatamodel failing on an upstream response stays a 500. The detail goes throughjsonable_encoder, because the error'sinputcan hold dates thatJSONResponsecannot serialize.exceptionis unchanged for this case.TimeoutError,asyncio.TimeoutError(its own class on Python 3.10) andrequests.Timeout(anOSError). The detail is the error's message or "The upstream data source did not respond in time."; arequeststimeout always gets the generic sentence, because its message can carry the request URL.json.JSONDecodeError,requests.exceptions.JSONDecodeErrorand aiohttp'sContentTypeError, which is whatresponse.json()raises for a blocked page served astext/html. The detail is "The data source returned a response that is not valid JSON."AppLoader.add_exception_handlersregisters each of these types by type. Handlers registered by type run inside the CORS middleware, so these responses keep their CORS headers.Tests
In
tests/api/test_exception_handlers.py:QueryParamsfields, with a date in the input, give a 422 list withloc: ["query", ...]for both and nourl;QueryParamssubclass whose name lacks "QueryParams" gives the same 422;Datafield stays a 500;TimeoutErrorwith and without a message,asyncio.TimeoutError,aiohttp.ServerTimeoutError,requestsConnectTimeoutandReadTimeout);jsonandrequestsJSONDecodeError, aiohttpContentTypeError).In
tests/api/test_app_loader.py: behindCORSMiddleware, the 504 and 502 responses carryaccess-control-allow-origin(four cases).The two files pass 35/35 on Python 3.12 and on 3.10.22. On 3.10 the
asyncio.TimeoutErrorandaiohttp.ServerTimeoutErrorcases fail without the explicit entry.openbb_platform/core/testspasses 2,260 with 36 skipped (Python 3.12); one test fails,tests/app/test_version.py::test_is_git_repo_true_for_repo_root, because the test container mounts onlycore/.Results from a deployment
OpenBQ's Docker image has run these two files as a build-time patch over openbb-core 2.0.1, which matches
developfor both files.500 Unexpected Error -> ValidationError, out of 100 500s for that class of request. With the deployed patch, a request without a required provider input answers 422 (this PR now returns it as a list withloc: ["query", "code"]). We checked this on/cftc/cot, withstart_datein the request so the error's input holds a date.Unexpected Error -> TimeoutError. They now answer 504.rest_apiapp. It passes 11/11; on unpatched 2.0.1 it had 7 failures and 1 error. The module also covers fix(core): mark required provider-only query params required in the widget #7752 and feat(core): optional per-provider deadline for commands #7753.Not included
ValueErrors still map to 422, as before.🤖 Generated with Claude Code