Skip to content

Fix AttributeError when metadata is null in request body - #17306

Merged
1 commit merged into
BerriAI:mainfrom
Chesars:fix/null-metadata-tags-17263
Dec 2, 2025
Merged

Fix AttributeError when metadata is null in request body#17306
1 commit merged into
BerriAI:mainfrom
Chesars:fix/null-metadata-tags-17263

Conversation

@Chesars

@Chesars Chesars commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Title

Fix AttributeError when metadata is null in request body

Relevant issues

Fixes #17263

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard
    requirement
    - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

When sending a request to /v1/batches (or other endpoints) with metadata: null, the proxy returns a 401 error with:

AttributeError: 'NoneType' object has no attribute 'get'

In get_tags_from_request_body(), the code uses request_body.get("metadata", {}) which returns None (not {}) when the key exists with a null value. Then metadata.get("tags", []) fails.

Fix: Changed to request_body.get("metadata") or {} which correctly handles both missing keys and explicit null values.

Files changed:

  • litellm/proxy/common_utils/http_parsing_utils.py - Fix the null metadata handling
  • tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py - Add regression test

No breaking changes

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

vercel Bot commented Dec 1, 2025

Copy link
Copy Markdown

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@ghost
ghost merged commit 01dfc35 into BerriAI:main Dec 2, 2025
4 of 6 checks passed
@Chesars
Chesars deleted the fix/null-metadata-tags-17263 branch December 2, 2025 10:48
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…) (BerriAI#17306)

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 pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /v1/batches - 401 Unauthorized - When Metadata is null

1 participant