fix(typing): deep-copy a read-only Mapping in delete_nested_value through a dict
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled

This commit is contained in:
mateo-berri 2026-10-23 19:04:40 -07:00
parent 9432192d68
commit caf9b3d380
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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"]}