diff --git a/octue/cloud/pub_sub/message_handler.py b/octue/cloud/pub_sub/message_handler.py index 60124e64d..98114c3a8 100644 --- a/octue/cloud/pub_sub/message_handler.py +++ b/octue/cloud/pub_sub/message_handler.py @@ -414,9 +414,9 @@ def _handle_result(self, message): """ logger.info("%r received an answer to question %r.", self.receiving_service, self.question_uuid) - if message["output_manifest"] is None: - output_manifest = None - else: + if message.get("output_manifest"): output_manifest = Manifest.deserialise(message["output_manifest"]) + else: + output_manifest = None - return {"output_values": message["output_values"], "output_manifest": output_manifest} + return {"output_values": message.get("output_values"), "output_manifest": output_manifest} diff --git a/octue/cloud/pub_sub/service.py b/octue/cloud/pub_sub/service.py index accebf880..867a0a4d2 100644 --- a/octue/cloud/pub_sub/service.py +++ b/octue/cloud/pub_sub/service.py @@ -236,17 +236,16 @@ def answer(self, question, heartbeat_interval=120, timeout=30): allow_save_diagnostics_data_on_crash=allow_save_diagnostics_data_on_crash, ) - if analysis.output_manifest is None: - serialised_output_manifest = None - else: - serialised_output_manifest = analysis.output_manifest.to_primitive() + result = {"type": "result"} + + if analysis.output_values is not None: + result["output_values"] = analysis.output_values + + if analysis.output_manifest is not None: + result["output_manifest"] = analysis.output_manifest.to_primitive() self._send_message( - { - "type": "result", - "output_values": analysis.output_values, - "output_manifest": serialised_output_manifest, - }, + message=result, topic=topic, attributes={"question_uuid": question_uuid, "is_question": False}, timeout=timeout, diff --git a/tests/cloud/pub_sub/test_service.py b/tests/cloud/pub_sub/test_service.py index 56e29c622..215337570 100644 --- a/tests/cloud/pub_sub/test_service.py +++ b/tests/cloud/pub_sub/test_service.py @@ -722,7 +722,7 @@ def test_child_messages_can_be_recorded_by_parent(self): self.assertEqual( parent.received_messages[4], - {"type": "result", "output_values": "Hello! It worked!", "output_manifest": None}, + {"type": "result", "output_values": "Hello! It worked!"}, ) def test_child_exception_message_can_be_recorded_by_parent(self):