Skip to content

Commit

Permalink
Fix setting task run mode in Edit Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Nov 12, 2024
1 parent 6391b47 commit d3c2b63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cylc/flow/network/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/network/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
RUNTIME_FIELD_TO_CFG_MAP,
Mutations,
Runtime,
runtime_schema_to_cfg,
sort_elements,
SortArgs,
)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d3c2b63

Please sign in to comment.