Skip to content

Commit

Permalink
fix(status): better json object casting
Browse files Browse the repository at this point in the history
JSONs can be dicts or arrays so we should handle casting them in a reliable way.
  • Loading branch information
AntoineDao committed Jan 29, 2021
1 parent 6678f05 commit 5896dc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion queenbee/io/inputs/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ def from_template(template: Union[DAGInputs, FunctionInputs], value: Any) -> Ste
if template.__class__ in [DAGJSONObjectInput, FunctionJSONObjectInput]:
if isinstance(template_dict['value'], str):
template_dict['value'] = json.loads(template_dict['value'])
return StepJSONObjectInput.parse_obj(template_dict)
try:
# Try to parse JSON as a dict
return StepJSONObjectInput.parse_obj(template_dict)
except:
# Try to parse JSON as an array
return StepArrayInput.parse_obj(template_dict)
7 changes: 6 additions & 1 deletion queenbee/io/outputs/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,9 @@ def from_template(template: Union[DAGOutputs, FunctionOutputs], value: Any) -> S
if template.__class__ in [DAGJSONObjectOutput, FunctionJSONObjectOutput]:
if isinstance(template_dict['value'], str):
template_dict['value'] = json.loads(template_dict['value'])
return StepJSONObjectOutput.parse_obj(template_dict)
try:
# Try to parse JSON as a dict
return StepJSONObjectOutput.parse_obj(template_dict)
except:
# Try to parse JSON as an array
return StepArrayOutput.parse_obj(template_dict)

0 comments on commit 5896dc7

Please sign in to comment.