mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix: validate response has request before using in BadRequestError
Previously, BadRequestError would use any passed httpx.Response object
directly. However, httpx.Response objects require a request attribute
to be set. When a response without a request was passed (e.g., in tests),
it would cause a RuntimeError: 'The request instance has not been set
on this response.'
Now we validate that the response has a valid request attribute before
using it. If not, we fall back to the cached minimal error response,
matching the behavior before the optimization commit 4e3e1d54f5.
Fixes test_context_window_exceeded_error_from_litellm_proxy test failure.
This commit is contained in:
parent
4e3e1d54f5
commit
c0d79a6d1c
1 changed files with 6 additions and 1 deletions
|
|
@ -142,7 +142,12 @@ class BadRequestError(openai.BadRequestError): # type: ignore
|
|||
self.litellm_debug_info = litellm_debug_info
|
||||
self.max_retries = max_retries
|
||||
self.num_retries = num_retries
|
||||
if response is not None and isinstance(response, httpx.Response):
|
||||
if (
|
||||
response is not None
|
||||
and isinstance(response, httpx.Response)
|
||||
and hasattr(response, "request")
|
||||
and response.request is not None
|
||||
):
|
||||
self.response = response
|
||||
else:
|
||||
self.response = _get_minimal_error_response()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue