From caf9b3d380c4514283f7c333fa30ef0ed2e1ccc1 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 23 Oct 2026 19:04:40 -0700 Subject: [PATCH] fix(typing): deep-copy a read-only Mapping in delete_nested_value through a dict --- litellm/litellm_core_utils/dot_notation_indexing.py | 3 +-- tests/unit/litellm_core_utils/test_dot_notation_indexing.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/litellm_core_utils/dot_notation_indexing.py b/litellm/litellm_core_utils/dot_notation_indexing.py index f86e28fbee7..818cf1b9695 100644 --- a/litellm/litellm_core_utils/dot_notation_indexing.py +++ b/litellm/litellm_core_utils/dot_notation_indexing.py @@ -214,8 +214,7 @@ def delete_nested_value( """ import copy - copied: Final = copy.deepcopy(data) - result: Final = copied if isinstance(copied, dict) else dict(copied) + result: Final = copy.deepcopy(data if isinstance(data, dict) else dict(data)) try: # Parse path into segments diff --git a/tests/unit/litellm_core_utils/test_dot_notation_indexing.py b/tests/unit/litellm_core_utils/test_dot_notation_indexing.py index 299b4a54f9f..7c670f1dac9 100644 --- a/tests/unit/litellm_core_utils/test_dot_notation_indexing.py +++ b/tests/unit/litellm_core_utils/test_dot_notation_indexing.py @@ -2,6 +2,7 @@ Tests for litellm.litellm_core_utils.dot_notation_indexing module. """ +from types import MappingProxyType from typing import Final import pytest @@ -134,3 +135,7 @@ class TestDeleteNestedValue: assert result == {"tags": ["a", "b"]} assert payload == {"tags": ["a", "b"], "secret": ["s"]} assert result["tags"] is not payload["tags"] + + def test_delete_accepts_a_read_only_mapping(self): + payload: Final = MappingProxyType({"tags": ["a"], "secret": ["s"]}) + assert delete_nested_value(payload, "secret") == {"tags": ["a"]}