Treat partial_json_parser AssertionError as incomplete JSON (#31975)

This commit is contained in:
Raghavendra Vedula
2026-07-22 23:25:25 +08:00
committed by GitHub
parent a9497e8d73
commit 4eaa5ca651
+9
View File
@@ -209,6 +209,15 @@ def _partial_json_loads(input_str: str, flags: Allow) -> Tuple[Any, int]:
obj, end = JSONDecoder().raw_decode(input_str, start)
return obj, end
raise
except AssertionError as e:
# partial_json_parser.fix_fast() asserts on some partial/ambiguous inputs
# (e.g. trailing non-whitespace after an otherwise-fixable prefix) instead
# of signaling "incomplete". Convert to JSONDecodeError so streaming
# callers treat it as not-yet-complete (wait for more tokens) rather than
# raising and failing the request.
raise JSONDecodeError(
"partial_json_parser assertion (treat as incomplete)", input_str, 0
) from e
def _is_complete_json(input_str: str) -> bool: