mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-22 00:31:44 +00:00
fix: add regression test for shallow copy boundary
Add test documenting that shallow copy isolates top-level key reassignment but not nested dict mutations (expected behavior).
This commit is contained in:
parent
5ddb335a31
commit
89ead20293
1 changed files with 24 additions and 0 deletions
|
|
@ -1643,3 +1643,27 @@ def test_logging_messages_isolated_tool_calls():
|
|||
# Reassign tool_calls on the original dict
|
||||
messages[0]["tool_calls"] = [{"id": "call_NEW", "type": "function", "function": {"name": "other", "arguments": "{}"}}]
|
||||
assert logging_obj.messages[0]["tool_calls"] == original_tool_calls
|
||||
|
||||
|
||||
def test_shallow_copy_nested_metadata_mutation_shared():
|
||||
"""Top-level key reassignment is isolated; nested dict mutation is shared (expected)."""
|
||||
original_messages = [
|
||||
{"role": "user", "content": "test", "metadata": {"key": "value"}}
|
||||
]
|
||||
logging_obj = LitellmLogging(
|
||||
model="gpt-4",
|
||||
messages=original_messages,
|
||||
stream=False,
|
||||
call_type="completion",
|
||||
start_time=time.time(),
|
||||
litellm_call_id="12345",
|
||||
function_id="1245",
|
||||
)
|
||||
|
||||
# Top-level key reassignment IS isolated by shallow copy
|
||||
original_messages[0]["content"] = "CHANGED"
|
||||
assert logging_obj.messages[0]["content"] == "test"
|
||||
|
||||
# Nested dict mutation is NOT isolated (shared reference) — expected
|
||||
original_messages[0]["metadata"]["key"] = "modified"
|
||||
assert logging_obj.messages[0]["metadata"]["key"] == "modified"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue