diff --git a/CHANGELOG.md b/CHANGELOG.md index ce00f1c..f8019a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Removed +## [1.4.9] - 2026-05-25 + +### Fixed + + - Updated error handling for MQ sending so that any errors sending dataset + check results doesn't cause checker loop to exit early. + ## [1.4.8] - 2026-05-18 ### Removed diff --git a/pyproject.toml b/pyproject.toml index 077a699..a6b6bc4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "bulk-data-service" -version = "1.4.8" +version = "1.4.9" requires-python = ">= 3.12.6" readme = "README.md" dependencies = [ diff --git a/src/utilities/azure.py b/src/utilities/azure.py index aa742ec..478228a 100644 --- a/src/utilities/azure.py +++ b/src/utilities/azure.py @@ -184,9 +184,14 @@ def send_dataset_check_result_message(context: BDSContext, msg_payload: dict, re try: send_message_to_iati_mq(context, topic_name, msg_payload) break - except azure.servicebus.exceptions.ServiceBusConnectionError as e: + except azure.servicebus.exceptions.ServiceBusError as e: if retry_number == retries: - raise RuntimeError("{}".format(e)) + context.logger.error( + "Dataset check result message could not be sent to the IATI MQ after {} attempts. " + "Error details: {}".format(retry_number, e) + ) + except Exception as e: + raise RuntimeError("{}".format(e)) def send_message_to_iati_mq(context: BDSContext, topic_name, msg_payload): diff --git a/tests/integration/test_dataset_update.py b/tests/integration/test_dataset_update.py index feb93ae..95a4880 100644 --- a/tests/integration/test_dataset_update.py +++ b/tests/integration/test_dataset_update.py @@ -2,6 +2,7 @@ import uuid import pytest +from azure.servicebus.exceptions import ServiceBusQuotaExceededError from bulk_data_service.checker import checker_run from helpers.data_helpers import ( @@ -199,6 +200,47 @@ def test_update_dataset_registration_details(get_and_clear_up_context, field, or assert datasets_in_bds[dataset_id][field] == expected +def test_update_dataset_mq_message_send_doesnt_crash_on_error(monkeypatch, get_and_clear_up_context): # noqa: F811 + + context = get_and_clear_up_context + + class FailingTopicSender: + def send_messages(self, *args, **kwargs): + raise ServiceBusQuotaExceededError( + message="Test simulated service bus send failure", + ) + + def close(self): + return None + + class FakeServiceBusClient: + def get_topic_sender(self, *args, **kwargs): + return FailingTopicSender() + + def close(self): + return None + + class FakeServiceFactory: + def get_service_bus_client(self, *args, **kwargs): + return FakeServiceBusClient() + + def get_suitecrm_client(self): + raise NotImplementedError + + monkeypatch.setattr(context, "_service_factory", FakeServiceFactory()) + + dataset_id = uuid.UUID("c8a40aa5-9f31-4bcf-a36f-51c1fc2cc159") + + context["DATA_REGISTRY_BASE_URL"] = "http://localhost:3000/ckan-registration/datasets-01-1-dataset" + datasets_in_bds = {} + checker_run(context, datasets_in_bds) + + context.logger.error.assert_called_once() + assert context.logger.error.call_args.args[0].startswith( + "Dataset check result message could not be sent to the IATI MQ" + ) + + def test_dataset_download_404s_then_successful(get_and_clear_up_context): # noqa: F811 context = get_and_clear_up_context