litellm/tests/test_litellm/proxy/spend_tracking
milan-berri efaafbbd02
fix(proxy): strip NUL bytes from spend log payloads to prevent PostgreSQL 22P05 (#29515)
A raw NUL byte (\x00) in request/response content is serialized by json.dumps
into the \u0000 JSON escape. When update_spend_logs writes this to the
LiteLLM_SpendLogs jsonb columns, Postgres rejects the whole batch with
error 22P05 ("unsupported Unicode escape sequence ... cannot be converted to
text"), crashing the periodic update_spend job and dropping the spend-log batch.

Centralize stripping in safe_dumps (covers metadata/response paths and any
future caller) and route the messages, proxy_server_request, request_tags, and
response (string branch) payloads through it instead of json.dumps. Dict keys
are stripped too.

Adds regression tests for safe_dumps and the spend-log message, response, and
request_tags payload builders.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 12:07:11 -07:00
..
test_cloudzero_endpoints.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_spend_log_error_logger.py feat(spend-logs): opt-in suppression of stack traces in spend-tracking error logs 2026-05-02 00:44:34 +00:00
test_spend_management_endpoints.py Litellm oss staging (#29492) 2026-06-02 08:48:10 -07:00
test_spend_query_optimization.py fix(spend): session-TZ-independent date filtering for spend/error log queries 2026-04-10 17:04:52 -07:00
test_spend_tracking_utils.py fix(proxy): strip NUL bytes from spend log payloads to prevent PostgreSQL 22P05 (#29515) 2026-06-02 12:07:11 -07:00