diff --git a/nhsn/delphi_nhsn/pull.py b/nhsn/delphi_nhsn/pull.py index 855c0952f..e05d42e9d 100644 --- a/nhsn/delphi_nhsn/pull.py +++ b/nhsn/delphi_nhsn/pull.py @@ -33,7 +33,6 @@ def check_last_updated(socrata_token, dataset_id, logger): ------- """ - recently_updated_source = True try: client = Socrata("data.cdc.gov", socrata_token) response = client.get_metadata(dataset_id) @@ -49,10 +48,11 @@ def check_last_updated(socrata_token, dataset_id, logger): ) else: logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp) + return recently_updated_source # pylint: disable=W0703 except Exception as e: - logger.info("error while processing socrata metadata; treating data as stale", error=str(e)) - return recently_updated_source + logger.error("error while processing socrata metadata", error=str(e)) + raise def pull_data(socrata_token: str, dataset_id: str, backup_dir: str, logger): diff --git a/nhsn/tests/test_pull.py b/nhsn/tests/test_pull.py index ec2de51ef..0c6da19e9 100644 --- a/nhsn/tests/test_pull.py +++ b/nhsn/tests/test_pull.py @@ -176,3 +176,17 @@ def test_check_last_updated(self, mock_socrata, dataset, updatedAt, caplog): stale_msg = f"{dataset['msg_prefix']}NHSN data is stale; Skipping" assert stale_msg in caplog.text + + + @patch("delphi_nhsn.pull.Socrata") + def test_check_last_updated_error(self, mock_socrata, caplog): + mock_client = MagicMock() + # mock metadata missing important field, "viewLastModified": + mock_client.get_metadata.return_value = {"rowsUpdatedAt": time.time()} + mock_socrata.return_value = mock_client + logger = get_structured_logger() + + with pytest.raises(KeyError): + check_last_updated("fakesocratatoken", MAIN_DATASET_ID, logger) + assert "error while processing socrata metadata" in caplog.text +