From ff7afc25b39478ff02b9f22eb6208629987d93b9 Mon Sep 17 00:00:00 2001 From: Jeremy Nelson Date: Mon, 4 Nov 2024 12:06:20 -0800 Subject: [PATCH 1/2] bug: Continues marc records if a record is None --- libsys_airflow/plugins/data_exports/marc/oclc.py | 4 ++++ tests/data_exports/test_oclc.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libsys_airflow/plugins/data_exports/marc/oclc.py b/libsys_airflow/plugins/data_exports/marc/oclc.py index 27382fef..76968f86 100644 --- a/libsys_airflow/plugins/data_exports/marc/oclc.py +++ b/libsys_airflow/plugins/data_exports/marc/oclc.py @@ -130,6 +130,10 @@ def divide(self, marc_file) -> None: if not i % 100: logger.info(f"{i:,} records processed") + if record is None: + logger.error(f"Record {i} is None") + continue + record_ids = get_record_id(record) campus_codes = self.determine_campus_code(record) diff --git a/tests/data_exports/test_oclc.py b/tests/data_exports/test_oclc.py index d39873f9..03d15d4b 100644 --- a/tests/data_exports/test_oclc.py +++ b/tests/data_exports/test_oclc.py @@ -372,7 +372,9 @@ def test_determine_campus_code_http_error(mocker, mock_folio_client): assert codes == [] -def test_oclc_division(mocker, tmp_path, mock_folio_client, sample_marc_records): +def test_oclc_division( + mocker, tmp_path, mock_folio_client, sample_marc_records, caplog +): mocker.patch( 'libsys_airflow.plugins.data_exports.marc.transformer.folio_client', @@ -385,10 +387,13 @@ def test_oclc_division(mocker, tmp_path, mock_folio_client, sample_marc_records) marc_writer = pymarc.MARCWriter(fo) for record in sample_marc_records: marc_writer.write(record) + fo.write(b"\n") oclc_transformer = OCLCTransformer() oclc_transformer.divide(marc_file=str(marc_file.absolute())) + assert "Record 3 is None" in caplog.text + assert len(oclc_transformer.libraries["STF"]["holdings"]) == 1 assert len(oclc_transformer.libraries["STF"]["marc"]) == 1 From 6fd34cd9e8c8a26cb6bb1ed1d4a7329189c19168 Mon Sep 17 00:00:00 2001 From: Jeremy Nelson Date: Mon, 4 Nov 2024 13:22:18 -0800 Subject: [PATCH 2/2] feature: Adds more detail to error message per PR review --- libsys_airflow/plugins/data_exports/marc/oclc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsys_airflow/plugins/data_exports/marc/oclc.py b/libsys_airflow/plugins/data_exports/marc/oclc.py index 76968f86..a903d924 100644 --- a/libsys_airflow/plugins/data_exports/marc/oclc.py +++ b/libsys_airflow/plugins/data_exports/marc/oclc.py @@ -131,7 +131,7 @@ def divide(self, marc_file) -> None: logger.info(f"{i:,} records processed") if record is None: - logger.error(f"Record {i} is None") + logger.error(f"Record {i} is None in {marc_file}") continue record_ids = get_record_id(record)