refactor(batch): read the row body without a mutable fallback literal

`(entry.get("body") or {})` counts as mutable-collection construction
(LIT002), and main has since lowered that ceiling. Check the body is a dict
instead; behaviour is unchanged.
This commit is contained in:
Mihidum Hettiyahandi 2026-09-17 09:21:32 +10:00
parent 8197b319e7
commit c8c9ef2690

View file

@ -981,7 +981,10 @@ class _PROXY_BatchRateLimiter(CustomLogger):
# estimate; floor it there again so a row carrying a
# large base64 audio payload cannot slide the batch
# under the TPM limit.
if messages_contain_input_audio_content_blocks((entry.get("body") or {}).get("messages")):
entry_body = entry.get("body") if isinstance(entry, dict) else None
if isinstance(entry_body, dict) and messages_contain_input_audio_content_blocks(
entry_body.get("messages")
):
entry_total_tokens = max(entry_total_tokens, _estimate_batch_entry_tokens(raw_line))
except Exception:
entry_total_tokens = _estimate_batch_entry_tokens(raw_line)