diff --git a/CHANGES.md b/CHANGES.md index 53693725efc..ea585698993 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -51,6 +51,9 @@ default job runner directives for platforms. ### Fixes +[#4975](https://github.com/cylc/cylc-flow/pull/4975) - Fix selection of +platforms from `[job]` and `[remote]` configs. + [#4970](https://github.com/cylc/cylc-flow/pull/4970) - Fix handling of suicide triggers in back-compat mode. diff --git a/cylc/flow/platforms.py b/cylc/flow/platforms.py index f9e32c4973b..2f783ebc3a5 100644 --- a/cylc/flow/platforms.py +++ b/cylc/flow/platforms.py @@ -138,8 +138,9 @@ def get_platform( # Need to calculate platform task_job_section: Dict[Any, Any] = {} task_remote_section: Dict[Any, Any] = {} - task_job_section = task_conf.get("job", {}) - task_remote_section = task_conf.get("remote", {}) + task_job_section = task_conf['job'] if 'job' in task_conf else {} + task_remote_section = ( + task_conf['remote'] if 'remote' in task_conf else {}) return platform_from_name( platform_from_job_info( glbl_cfg(cached=False).get(['platforms']), diff --git a/tests/unit/test_platforms.py b/tests/unit/test_platforms.py index afd3bb57cae..5491fca6532 100644 --- a/tests/unit/test_platforms.py +++ b/tests/unit/test_platforms.py @@ -22,6 +22,7 @@ from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults from cylc.flow.platforms import ( get_all_platforms_for_install_target, + get_platform, get_platform_deprecated_settings, get_random_platform_for_install_target, is_platform_definition_subshell, platform_from_name, platform_from_job_info, @@ -34,6 +35,8 @@ PlatformLookupError, GlobalConfigError ) +from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults + PLATFORMS = { 'desktop[0-9]{2}|laptop[0-9]{2}': { @@ -599,3 +602,33 @@ def test_is_platform_definition_subshell( assert err_msg in str(exc.value) else: assert is_platform_definition_subshell(plat_val) is expected + + +def test_get_platform_from_OrderedDictWithDefaults(mock_glbl_cfg): + """Get platform works with OrderedDictWithDefaults. + + Most tests use dictionaries to check platforms functionality. + This one was added to catch an issue where the behaviour of + dict.get != OrderedDictWithDefaults.get. + """ + mock_glbl_cfg( + 'cylc.flow.platforms.glbl_cfg', + ''' + [platforms] + [[skarloey]] + hosts = foo, bar + job runner = slurm + ''' + ) + task_conf = OrderedDictWithDefaults() + task_conf.defaults_ = dict([ + ('job', dict([ + ('batch system', 'slurm') + ])), + ('remote', dict([ + ('host', 'foo') + ])) + ]) + result = get_platform(task_conf)['name'] + assert result == 'skarloey' +