mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
Handle the case where metadata is explicitly set to null/None in the
request body. This was causing a 401 error with "'NoneType' object
has no attribute 'get'" when calling /v1/batches with metadata: null.
The fix uses `or {}` instead of a default dict value since the key
exists but has a None value.
This commit is contained in:
parent
965406c643
commit
01dfc3561a
2 changed files with 22 additions and 3 deletions
|
|
@ -309,7 +309,7 @@ def get_tags_from_request_body(request_body: dict) -> List[str]:
|
|||
List of tag names (strings), empty list if no valid tags found
|
||||
"""
|
||||
metadata_variable_name = get_metadata_variable_name_from_kwargs(request_body)
|
||||
metadata = request_body.get(metadata_variable_name, {})
|
||||
metadata = request_body.get(metadata_variable_name) or {}
|
||||
tags_in_metadata: Any = metadata.get("tags", [])
|
||||
tags_in_request_body: Any = request_body.get("tags", [])
|
||||
combined_tags: List[str] = []
|
||||
|
|
|
|||
|
|
@ -606,8 +606,27 @@ def test_get_tags_from_request_body_with_dict_tags():
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result = get_tags_from_request_body(request_body=request_body)
|
||||
|
||||
|
||||
assert result == []
|
||||
assert isinstance(result, list)
|
||||
|
||||
|
||||
def test_get_tags_from_request_body_with_null_metadata():
|
||||
"""
|
||||
Test that function handles null metadata gracefully without crashing.
|
||||
|
||||
This is a regression test for https://github.com/BerriAI/litellm/issues/17263
|
||||
When metadata is explicitly set to null/None, the function should return
|
||||
an empty list instead of raising AttributeError.
|
||||
"""
|
||||
request_body = {
|
||||
"model": "gpt-4",
|
||||
"metadata": None # OpenAI API accepts metadata: null
|
||||
}
|
||||
|
||||
result = get_tags_from_request_body(request_body=request_body)
|
||||
|
||||
assert result == []
|
||||
assert isinstance(result, list)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue