mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix: handle non-picklable original_exception in MidStreamFallbackError
The __getstate__ mixin was storing attributes as-is into the pickle state dict. For openai SDK exceptions (e.g. openai.RateLimitError), pickle.dumps succeeds but pickle.loads fails because the openai __init__ requires response and body keyword arguments that the default pickle reconstruction does not supply. Fix: probe each non-httpx attribute with a full round-trip (pickle.loads(pickle.dumps(v))) before storing it. If the round-trip fails, store str(v) instead so the attribute is still meaningful after unpickling. Covers MidStreamFallbackError.original_exception and any other attribute that is dumps-able but not loads-able.
This commit is contained in:
parent
f8b0615ae9
commit
1113598c57
1 changed files with 6 additions and 1 deletions
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
## LiteLLM versions of the OpenAI Exception Types
|
||||
|
||||
import pickle
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
|
|
@ -87,7 +88,11 @@ class _LiteLLMPickleMixin:
|
|||
elif isinstance(v, httpx.Request):
|
||||
http_attrs.append(k)
|
||||
else:
|
||||
state[k] = v
|
||||
try:
|
||||
pickle.loads(pickle.dumps(v))
|
||||
state[k] = v
|
||||
except Exception:
|
||||
state[k] = str(v)
|
||||
if http_attrs:
|
||||
state["_pickled_http_attrs"] = http_attrs
|
||||
return state
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue