diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index afe059ce1e..db6eefc926 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -71,11 +71,27 @@ def print_verbose(print_statement): def safe_deep_copy(data): + """ + Safe Deep Copy + + The LiteLLM Request has some object that can-not be pickled / deep copied + + Use this function to safely deep copy the LiteLLM Request + """ + + # Step 1: Remove the litellm_parent_otel_span if isinstance(data, dict): # remove litellm_parent_otel_span since this is not picklable if "metadata" in data and "litellm_parent_otel_span" in data["metadata"]: data["metadata"].pop("litellm_parent_otel_span") new_data = copy.deepcopy(data) + + # Step 2: re-add the litellm_parent_otel_span after doing a deep copy + if isinstance(data, dict): + if "metadata" in data and "litellm_parent_otel_span" in data["metadata"]: + data["metadata"]["litellm_parent_otel_span"] = data["metadata"][ + "litellm_parent_otel_span" + ] return new_data @@ -2891,6 +2907,7 @@ missing_keys_html_form = """ def _to_ns(dt): return int(dt.timestamp() * 1e9) + def get_error_message_str(e: Exception) -> str: error_message = "" if isinstance(e, HTTPException):