Skip to content

Commit

Permalink
Safeguard by checking dict-like before iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaris committed Mar 4, 2022
1 parent bfad9ab commit ba71e25
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/indra_cogex/apps/query_web_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ def process_result(result) -> Any:
# Any fundamental type
if isinstance(result, (int, str, bool, float)):
return result
# Any dict query
elif isinstance(result, (dict, Mapping, Counter)):
res_dict = dict(result)
return {k: process_result(v) for k, v in res_dict.items()}
# Any iterable query
elif isinstance(result, (Iterable, list, set)):
list_res = list(result)
# Check for empty list
if list_res and hasattr(list_res[0], "to_json"):
list_res = [res.to_json() for res in list_res]
return list_res
# Any dict query
elif isinstance(result, (dict, Mapping, Counter)):
res_dict = dict(result)
return {k: process_result(v) for k, v in res_dict.items()}
else:
raise TypeError(f"Don't know how to process result of type {type(result)}")

Expand Down

0 comments on commit ba71e25

Please sign in to comment.