mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-19 09:53:33 +00:00
fix(typing): deep-copy a read-only Mapping in delete_nested_value through a dict
This commit is contained in:
parent
9432192d68
commit
caf9b3d380
2 changed files with 6 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"]}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue