Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glbl_cfg: reload without mutating the original #6249

Merged
merged 2 commits into from
Jul 23, 2024
Merged

Conversation

oliver-sanders
Copy link
Member

@oliver-sanders oliver-sanders commented Jul 19, 2024

Sibling: cylc/cylc-rose#336

  • Use the new reload kwarg rather than calling the .load() method.
  • Fixes glblcfg: platform not found #6244
  • The .load() method mutates the existing config, due to the use of logging within (and outside of) this routine and the use of glbl_cfg in the logging, this created a race condition.
  • The new reload kwarg creates a new config instance, then sets this as the default.

To assert that the test captures the issue, try applying this diff to test the old reload method:

diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py
index 231fb12f8..eb56ed5cb 100644
--- a/tests/integration/test_config.py
+++ b/tests/integration/test_config.py
@@ -588,7 +588,9 @@ async def test_glbl_cfg(monkeypatch, tmp_path, caplog):
     # * but during the reload itself, the old config should persist
     #   see https://github.com/cylc/cylc-flow/issues/6244
     expect_platforms_during_reload({'localhost', 'foo'})
-    assert get_platforms(glbl_cfg(reload=True)) == {'localhost', 'foo', 'bar'}
+    cfg = glbl_cfg()
+    cfg.load()
+    assert get_platforms(cfg) == {'localhost', 'foo', 'bar'}
     assert 'ran expect_platforms_during_reload test' in caplog.messages
 
     # the cache should have been updated by the reload

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@oliver-sanders oliver-sanders added the bug Something is wrong :( label Jul 19, 2024
@oliver-sanders oliver-sanders added this to the 8.3.3 milestone Jul 19, 2024
@oliver-sanders oliver-sanders marked this pull request as draft July 19, 2024 12:45
@oliver-sanders oliver-sanders force-pushed the 6244 branch 2 times, most recently from 5e0aa62 to 93bf977 Compare July 19, 2024 14:21
* Use the new `reload` kwarg rather than calling the `.load()` method.
* Fixes cylc#6244
* The `.load()` method mutates the existing config, due to the use of
  logging within (and outside of) this routine and the use of
  `glbl_cfg` in the logging, this created a race condition.
* The new `reload` kwarg creates a new config instance, then sets
  this as the default.
@oliver-sanders oliver-sanders marked this pull request as ready for review July 19, 2024 14:33
@oliver-sanders oliver-sanders requested review from hjoliver and wxtim July 19, 2024 14:34
"""Return the platforms defined in the provided config instance."""
return {p for p in cfg_obj.get(['platforms']).keys()}

def expect_platforms_during_reload(platforms):
Copy link
Member

@wxtim wxtim Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 I enjoy learning about stuff when I review and this is rather clever.

Copy link
Member

@wxtim wxtim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Happy with code
  • Tried locally
  • Test fails against 8.3.x (and not just because it has an unrecognized keyword arg)

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

(Two approvals, but @MetRonnie has an unresolved comment)

@wxtim wxtim merged commit 2749991 into cylc:8.3.x Jul 23, 2024
27 checks passed
@MetRonnie MetRonnie linked an issue Jul 23, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong :(
Projects
None yet
Development

Successfully merging this pull request may close these issues.

glblcfg: platform not found
4 participants