From 69928449f7fc89cc95a9becc723a22c0dbafb009 Mon Sep 17 00:00:00 2001 From: Harshit28j Date: Fri, 20 Mar 2026 23:57:00 +0530 Subject: [PATCH] fix req changes by greptile --- litellm/litellm_core_utils/litellm_logging.py | 2 +- .../litellm_core_utils/test_litellm_logging.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 23ad82e0979..6b281b911fe 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -620,7 +620,7 @@ class Logging(LiteLLMLoggingBaseClass): if "litellm_metadata" in kwargs and isinstance( kwargs["litellm_metadata"], dict ): - if "metadata" not in base_litellm_params: + if not base_litellm_params.get("metadata"): base_litellm_params["metadata"] = dict(kwargs["litellm_metadata"]) else: base_litellm_params["metadata"] = dict(base_litellm_params["metadata"]) diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py index 3798f5ea33e..19cfcce9668 100644 --- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py +++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py @@ -467,6 +467,19 @@ class TestUpdateFromKwargs: assert result_meta["from_caller"] is True assert result_meta["user_api_key_hash"] == "hashed-xyz" + def test_merge_handles_metadata_none(self, logging_obj): + """When metadata=None is explicitly in kwargs alongside litellm_metadata, + the merge should not crash (dict(None) would TypeError).""" + kwargs = { + "metadata": None, + "litellm_metadata": {"user_api_key_hash": "hashed-abc"}, + } + + logging_obj.update_from_kwargs(kwargs=kwargs) + + result_meta = logging_obj.litellm_params["metadata"] + assert result_meta["user_api_key_hash"] == "hashed-abc" + def test_caller_litellm_params_win_over_kwargs(self, logging_obj): """Explicit litellm_params from the caller should override auto-extracted values.""" kwargs = {"metadata": {"from_kwargs": True}}