From 97c45e995d58d2c53e66789f37028eef60242b01 Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Mon, 25 May 2026 10:34:51 +0100 Subject: [PATCH 1/4] test: add regression test for error MQ handling This adds a regression test which ensures robust handling of errors when sending dataset check results. --- tests/integration/test_dataset_update.py | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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 From 16bfe8aab4b1877664d5fadbd61fc73761732050 Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Mon, 25 May 2026 10:35:25 +0100 Subject: [PATCH 2/4] fix: robust handling of MQ errors in checker loop --- src/utilities/azure.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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): From 8bc27ad522e7010dc2af80cd9ba4bb33ced8f7ef Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Mon, 25 May 2026 10:35:36 +0100 Subject: [PATCH 3/4] build: bump version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = [ From 23ee68b0798ec9c743c99136e3a907296a5750d1 Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Mon, 25 May 2026 10:35:42 +0100 Subject: [PATCH 4/4] docs: update CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) 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