From 6391b4703f2101c3fa3f237dc6bde000c2333ed6 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:39:36 +0000 Subject: [PATCH 1/2] Fix run mode printed in scheduler log --- cylc/flow/scheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cylc/flow/scheduler.py b/cylc/flow/scheduler.py index b8604c54cf..ab68b454b6 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( From d3c2b639bad63b77628fb85d6661c2bffbfcc156 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:53:34 +0000 Subject: [PATCH 2/2] Fix setting task run mode in Edit Runtime --- cylc/flow/network/resolvers.py | 8 +++----- cylc/flow/network/schema.py | 14 ++++++++++++++ tests/unit/network/test_schema.py | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cylc/flow/network/resolvers.py b/cylc/flow/network/resolvers.py index fc9b67eeef..79b91f97ee 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 2e7bd789db..6388b7b7e8 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/tests/unit/network/test_schema.py b/tests/unit/network/test_schema.py index 5f92cb4a35..1604cadfb0 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()