From 1a549c82b057ed6877e2fb4a6110d6f777821996 Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Mon, 4 Apr 2022 13:45:57 -0400 Subject: [PATCH] Adding assert to static tasks for data type --- .../static_task/static_agent_state.py | 4 ++++ mephisto/operations/client_io_handler.py | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py b/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py index 82a7f223b..af70d187d 100644 --- a/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py +++ b/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py @@ -97,6 +97,10 @@ def update_data(self, live_update: Dict[str, Any]) -> None: def update_submit(self, submission_data: Dict[str, Any]) -> None: """Move the submitted output to the local dict""" outputs: Dict[str, Any] + assert isinstance(submission_data, dict), ( + "Static tasks must get dict results. Ensure you are passing an object to " + f"your frontend task's `handleSubmit` method. Got {submission_data}" + ) output_files = submission_data.get("files") if output_files is not None: submission_data["files"] = [f["filename"] for f in submission_data["files"]] diff --git a/mephisto/operations/client_io_handler.py b/mephisto/operations/client_io_handler.py index 888515c27..0a6e781a8 100644 --- a/mephisto/operations/client_io_handler.py +++ b/mephisto/operations/client_io_handler.py @@ -272,15 +272,18 @@ def _on_submit_unit(self, packet: Packet, _channel_id: str): agent = live_run.worker_pool.get_agent_for_id(packet.subject_id) assert agent is not None, "Could not find given agent!" - # If the packet is_submit, and has files, we need to - # process downloading those files first - data_files = packet.data.get("files") - if data_files is not None: - save_dir = agent.get_data_dir() - architect = live_run.architect - for f_obj in data_files: - # TODO(#649) this is incredibly blocking! - architect.download_file(f_obj["filename"], save_dir) + # Special handler for file downloads while we have architect access + # NOTE: this is a leaky abstraction at the moment - only architects + # know how to save files but "file saving" methods are defined by + # AgentStates, which don't have architect access. + if isinstance(packet.data, dict): + data_files = packet.data.get("files") + if data_files is not None: + save_dir = agent.get_data_dir() + architect = live_run.architect + for f_obj in data_files: + # TODO(#649) this is incredibly blocking! + architect.download_file(f_obj["filename"], save_dir) agent.handle_submit(packet.data)