Skip to content

Commit

Permalink
FIX: Raise error if service revision doesn't exist when no registry
Browse files Browse the repository at this point in the history
  • Loading branch information
cortadocodes committed Aug 26, 2024
1 parent db1fbe3 commit 37e5788
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion octue/cloud/pub_sub/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
7 changes: 7 additions & 0 deletions tests/cloud/pub_sub/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 37e5788

Please sign in to comment.