Reload custom Jinja2 extensions - #7387
Conversation
Custom workflow filters, tests, and globals remained cached after their source files changed, so workflow reloads kept the old behavior. Reload matching local modules when rebuilding the Jinja environment and cover the stale-filter regression.
|
Hi, thanks for your interest in this issue. Out of interest, why did you pick the reload interface used here, which alternatives were considered? We haven't fully narrowed the scope of the issue yet so there's a bit of an investigation component to this, there are likely to be scenarios other than the one example explicitly given in #7385. For example, there can be Python files in a workflow other than Jinja2 extensions and imports can also lie outside of a workflow. This fix will need to hash out all of the possible scenarios where changes could be made to Python files between workflow being started and reloaded, and how Cylc will behave in each scenario which we should then back up with tests. |
|
Good questions, and fair — I jumped to an implementation before the scope was settled. To answer directly: I picked the Jinja2-extension reload path because #7385's example was specifically about a custom Jinja2 extension not being picked up on reload, so I hooked the reload where the Jinja2 environment is rebuilt. It was the narrowest change that fixed the reported case, not a considered take on the broader problem. You're right that it doesn't generalize. The cases I hadn't accounted for:
So this PR as-is only covers one branch of a bigger decision tree. I'm happy to either (a) narrow it explicitly to "Jinja2 extensions only" with that scope documented, and leave the broader Python-reload question to a separate design discussion, or (b) hold it while the scope gets hashed out if you'd rather solve it whole. What's your preference? |
|
It might still be worth merging this as-is on the basis that is a small straightforward change and users would naturally expect that a modified and reinstalled Jinja2 filter should be picked up on reload - so this is still an improvement toward the more general goal, and the implementation here will be very easy to modify in future if a more general solution is found. What do you think @oliver-sanders ? |
|
This might not be far off of the full solution, it just needs a little thought... Before we review/merge, we should work out the list of scenarios to which bug #7385 applies. For example:
The desired behaviour in all scenarios, is that any changes made to Python files should take effect when the workflow is reinstalled & reloaded (see the We may or may not be able to address all scenarios, but we need to work out what they are so we can document this fix as well as any outstanding caveats which we don't plan to address. We could also do with tests for these. @Sanjays2402, would you be able to help with this? For reference, see: |
|
On the interface choice: I went with the reload path because that's where the stale module is actually observable, and it keeps the change local rather than touching install. I didn't seriously evaluate invalidating at install time, which is probably the other candidate given Agree on scoping it properly first. The scenarios I can see are: (1) a Jinja2 filter/extension changed then reloaded, (2) a module under the workflow's Happy to write those up as tests. Worth agreeing the expected behaviour for (3) before I do, since that's the one where "correct" is a judgement call rather than obvious. |
I suspect we cannot reasonably "cascade" the reload down to imports of imports, etc, so it is completely reasonable for this to be a documented caveat. The main concern from the Cylc perspective is that files directly managed by Cylc (i.e, by install/reinstall) adhere to the lifecycle of Cylc operations (e.g, config, play, reload). |
|
Agreed on (3) — cascading down through imports of imports isn't something we can do safely, so a documented caveat it is. On the "files directly managed by Cylc" point, I went and checked what the current patch actually covers, and it's narrower than I'd claimed. Scenario matrix as it stands:
So (2) is the gap, and it's squarely in "files Cylc manages". The tractable version is to invalidate Two things I'd like your call on before I write it:
Either way I'll add functional tests covering (1) and (2) plus a doc note for (3) and (4). |
Closes #7385
Custom workflow Jinja2 modules remained cached across reload, so edited filters, tests, and globals kept their old behavior. This reloads matching local modules when rebuilding the Jinja environment and adds a regression test.
Check List
CONTRIBUTING.mdand added my name as a Code Contributor.setup.cfg(andconda-environment.ymlif present).?.?.xbranch.