From 37e5788116b6cb8f544bb8b78a77ca1d9aecd225 Mon Sep 17 00:00:00 2001 From: cortadocodes Date: Mon, 26 Aug 2024 13:45:34 +0100 Subject: [PATCH] FIX: Raise error if service revision doesn't exist when no registry --- octue/cloud/pub_sub/service.py | 13 ++++++++++++- tests/cloud/pub_sub/test_service.py | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/octue/cloud/pub_sub/service.py b/octue/cloud/pub_sub/service.py index 8a55e0383..b091a6aae 100644 --- a/octue/cloud/pub_sub/service.py +++ b/octue/cloud/pub_sub/service.py @@ -338,7 +338,18 @@ def ask( service_registries=self.service_registries, ) - elif not service_revision_tag: + elif service_revision_tag: + pub_sub_id = convert_service_id_to_pub_sub_form(service_id) + + service_revision_subscription = Subscription( + name=".".join((OCTUE_SERVICES_PREFIX, pub_sub_id)), + topic=self.services_topic, + ) + + if not service_revision_subscription.exists(): + raise octue.exceptions.ServiceNotFound(f"Service revision {service_id!r} not found.") + + else: raise octue.exceptions.InvalidServiceID( f"A service revision tag for {service_id!r} must be provided if service registries aren't being used." ) diff --git a/tests/cloud/pub_sub/test_service.py b/tests/cloud/pub_sub/test_service.py index b698a8cca..7d4dd1233 100644 --- a/tests/cloud/pub_sub/test_service.py +++ b/tests/cloud/pub_sub/test_service.py @@ -121,6 +121,13 @@ def test_missing_services_topic_results_in_error(self): with self.assertRaises(exceptions.ServiceNotFound): service.services_topic + def test_error_raised_if_service_revision_not_found_when_not_using_service_registry(self): + """Test that an error is raised if a service revision isn't found when not using a service registry.""" + service = MockService(backend=BACKEND) + + with self.assertRaises(exceptions.ServiceNotFound): + service.ask("non/existent:service") + def test_ask_unregistered_service_revision_when_service_registries_specified_results_in_error(self): """Test that an error is raised if attempting to ask an unregistered service a question when service registries are being used.