mirror of
https://github.com/tiennm99/litellm.git
synced 2026-06-18 00:48:01 +00:00
[Fix] Include all SpendLogsMetadata keys in spend logs payload
The dict comprehension in _get_spend_logs_metadata was only including metadata keys that existed in the input dict. After user_api_key_project_id was added to SpendLogsMetadata, payloads missing that key in input would not include it in output, causing test_spend_logs_payload to fail. Use metadata.get(key) instead of filtering with `if key in metadata` to ensure all SpendLogsMetadata keys are always present (defaulting to None), consistent with the metadata-is-None branch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -96,9 +96,8 @@ def _get_spend_logs_metadata(
|
||||
# Filter the metadata dictionary to include only the specified keys
|
||||
clean_metadata = SpendLogsMetadata(
|
||||
**{ # type: ignore
|
||||
key: metadata[key]
|
||||
key: metadata.get(key)
|
||||
for key in SpendLogsMetadata.__annotations__.keys()
|
||||
if key in metadata
|
||||
}
|
||||
)
|
||||
clean_metadata["applied_guardrails"] = applied_guardrails
|
||||
|
||||
Reference in New Issue
Block a user