[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:
yuneng-jiang
2026-02-19 11:27:09 -08:00
parent ddc1371cea
commit ccecc10c82
@@ -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