diff --git a/cylc/flow/network/resolvers.py b/cylc/flow/network/resolvers.py index fc9b67eeef5..79b91f97ee7 100644 --- a/cylc/flow/network/resolvers.py +++ b/cylc/flow/network/resolvers.py @@ -49,10 +49,10 @@ from cylc.flow.id import Tokens from cylc.flow.network.schema import ( DEF_TYPES, - RUNTIME_FIELD_TO_CFG_MAP, NodesEdges, PROXY_NODES, SUB_RESOLVERS, + runtime_schema_to_cfg, sort_elements, ) @@ -791,10 +791,8 @@ def broadcast( # Convert schema field names to workflow config setting names if # applicable: for i, dict_ in enumerate(settings): - settings[i] = { - RUNTIME_FIELD_TO_CFG_MAP.get(key, key): value - for key, value in dict_.items() - } + settings[i] = runtime_schema_to_cfg(dict_) + if mode == 'put_broadcast': return self.schd.task_events_mgr.broadcast_mgr.put_broadcast( cycle_points, namespaces, settings) diff --git a/cylc/flow/network/schema.py b/cylc/flow/network/schema.py index 2e7bd789dbf..6388b7b7e87 100644 --- a/cylc/flow/network/schema.py +++ b/cylc/flow/network/schema.py @@ -860,6 +860,20 @@ class Meta: """Map GQL Runtime fields' names to workflow config setting names.""" +def runtime_schema_to_cfg(runtime: dict) -> dict: + """Covert GQL Runtime field names to workflow config setting names and + perform any necessary processing on the values.""" + # We have to manually lowercase the run_mode field because we don't define + # a proper schema for BroadcastSetting (it's just GenericScalar) so + # Graphene has no way to know that it should be a TaskRunMode enum. + return { + RUNTIME_FIELD_TO_CFG_MAP.get(key, key): ( + value.lower() if key == 'run_mode' else value + ) + for key, value in runtime.items() + } + + class Job(ObjectType): class Meta: description = "Jobs." diff --git a/cylc/flow/scheduler.py b/cylc/flow/scheduler.py index b8604c54cfd..ab68b454b63 100644 --- a/cylc/flow/scheduler.py +++ b/cylc/flow/scheduler.py @@ -604,7 +604,7 @@ def log_start(self) -> None: # Note that the following lines must be present at the top of # the workflow log file for use in reference test runs. LOG.info( - f'Run mode: {self.get_run_mode()}', + f'Run mode: {self.get_run_mode().value}', extra=RotatingLogFileHandler.header_extra ) LOG.info( diff --git a/tests/unit/network/test_schema.py b/tests/unit/network/test_schema.py index 5f92cb4a35c..1604cadfb0a 100644 --- a/tests/unit/network/test_schema.py +++ b/tests/unit/network/test_schema.py @@ -26,6 +26,7 @@ RUNTIME_FIELD_TO_CFG_MAP, Mutations, Runtime, + runtime_schema_to_cfg, sort_elements, SortArgs, ) @@ -105,6 +106,20 @@ def test_runtime_field_to_cfg_map(field_name: str): assert WORKFLOW_SPEC.get('runtime', '__MANY__', cfg_name) +@pytest.mark.parametrize('runtime_dict,expected', [ + pytest.param( + {'run_mode': 'Skip'}, {'run mode': 'skip'}, id='edit-runtime' + ), + pytest.param( + {'run mode': 'skip'}, {'run mode': 'skip'}, id='broadcast' + ), +]) +def test_runtime_schema_to_cfg(runtime_dict, expected): + """Test this function can handle Edit Runtime submitted values as well + as normal broadcast values.""" + assert runtime_schema_to_cfg(runtime_dict) == expected + + @pytest.mark.parametrize('mutation', ( pytest.param(attr, id=name) for name, attr in Mutations.__dict__.items()