From c1b57fb2463888e4f1182fc8424987cabead3f7f Mon Sep 17 00:00:00 2001 From: feng-tao Date: Wed, 19 Aug 2020 10:52:59 -0700 Subject: [PATCH] chore: fix rest_api_query to do basic check Signed-off-by: feng-tao --- databuilder/rest_api/rest_api_query.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/databuilder/rest_api/rest_api_query.py b/databuilder/rest_api/rest_api_query.py index 571894b1e..39f9ece7d 100644 --- a/databuilder/rest_api/rest_api_query.py +++ b/databuilder/rest_api/rest_api_query.py @@ -153,7 +153,7 @@ def execute(self) -> Iterator[Dict[str, Any]]: # noqa: C901 result_list: List[Any] = [match.value for match in self._jsonpath_expr.find(response_json)] if not result_list: - log_msg = 'No result from URL: {url} , JSONPATH: {json_path} , response payload: {response}' \ + log_msg = 'No result from URL: {url}, JSONPATH: {json_path} , response payload: {response}' \ .format(url=self._url, json_path=self._json_path, response=response_json) LOGGER.info(log_msg) @@ -172,6 +172,9 @@ def execute(self) -> Iterator[Dict[str, Any]]: # noqa: C901 json_path_contains_or=self._json_path_contains_or) for sub_record in sub_records: + if not sub_record or len(sub_record) != len(self._field_names): + # skip the record + continue record_dict = copy.deepcopy(record_dict) for field_name in self._field_names: record_dict[field_name] = sub_record.pop(0)