fix: guard json.loads() in JSON tensor parsing — prevent hard crash on None or malformed tensor values#233
Open
amathxbt wants to merge 1 commit intoOpenGradient:mainfrom
Open
Conversation
…lformed/missing values Two unguarded json.loads() calls in _conversions.py would raise JSONDecodeError or TypeError when a JSON tensor's value field is None or not valid JSON. Also added a None-name guard to avoid silently inserting None keys into the output dict. Affected functions: - convert_to_model_output (event-based output path) - convert_array_to_model_output (array-based output path)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Fix: Unguarded
json.loads()crashes entire client when JSON tensor value isNoneor malformedSummary
Two unguarded
json.loads()calls in_conversions.pycause a hard crash whenever a JSON tensor's value field is missing or contains invalid JSON. Also found a missingNonecheck on tensor names that silently corrupts the output dictionary.Bug 1 —
convert_to_model_output: unguardedjson.loads(value)If
valueisNone(field missing from the response) →TypeError: the JSON object must be str, bytes or bytearray, not NoneTypeIf
valueis a malformed JSON string →json.JSONDecodeErrorBoth crash the entire inference call with a traceback that gives no useful context.
Bug 2 —
convert_array_to_model_output: same unguardedjson.loads(value)Bug 3 —
Nonetensor name silently corrupts output dictIn both functions, if
nameisNone(missing from the response), the code does:This inserts a
Nonekey into the output dict without any warning, making it impossible for callers to use the result correctly.Fix
Wrapped both
json.loads()calls intry/except (json.JSONDecodeError, TypeError)and added aNonename guard with acontinue+logging.warning()in both functions.Impact
Any model whose output includes a JSON tensor with a missing or malformed value field will crash the entire SDK client mid-inference with no useful error message. This affects both the event-based (
convert_to_model_output) and array-based (convert_array_to_model_output) output paths.