Hi, I’m trying to run an LFRic rose stem using Cylc 8 as:
%> rose stem --group=developer --opt-conf-key=$platform --source=lfric=$lfric $PWD/rose-stem
%> cylc play lfric_multi_thread
This rose stem runs without problem in Cylc 7, but in Cylc 8 Jinja2 throws up an error when processing some of the macros. The first error is given as:
I’ve taken a look at this, it seems that Cylc 8 is providing the same Jinja2 variables to the workflow as Cylc 7 was so it doesn’t look like an issue with Cylc.
The error is coming from within the Jinja2 logic contained in the workflow itself. We’ve recently added some advice for debugging Jinja2 code into the Cylc documentation which might help.
In this function Jinja2Globals/get_target_property.py::get_target_property.
After a bit of investigation it looks like context.vars is empty in certain situations. The offending call is coming from the macro called scripting. The target variable is set in this macro, however, it doesn’t seem to be present in context.vars. This might be a Jinja2 bug, I don’t know enough about @contextfunction to say for sure.
It appears that the target variable is present directly in the context variable so I managed to shift the error by making the following change:
@contextfunction
def get_target_property(context, target_dets, prop_path=None, compiler=None):
if prop_path is not None:
path_parts = prop_path.split('.')
else:
path_parts = []
- subtree = context.vars['target'][target_dets['platform']]
+ subtree = context['target'][target_dets['platform']]
while len(path_parts) > 0:
Thanks for your responses @oliver.sanders , @wxtim , this gives me something to work with. Great to know that this is most likely a Jinja2, not Cylc8 issue. Is there a list of known Jinja2 bugs somewhere that I could look through?
I just tried loading Jinja2 v3.1.2 (as opposed to version 3.0.3, which I gather is the default for Cylc 8.0.1), and got the following error when running cylc check ...:
Jinja2Error: cannot import name 'contextfilter' from 'jinja2' (/g/data/dp9/dl9118/jinja2/3.1.2/lib/python3.9/site-packages/jinja2/__init__.py)
I can see that the filter functions that are imported in the v3.0.3 __init__.py file from filters.py no longer exist in Jinja2 v3.1.2. I guess more recent versions of Jinja2 are not supported yet for Cylc8, is this correct?
but… it’s been pinned to keep the back-compatibility available at 3.0.* - there are more changes to Jinja2 at 3.1.* of which the removal of contextfilter is one - you’ve just previewed the issues you’ll have with Jinja2 changes when you change from version 3.0 to 3.1.
Jinja2 deprecated some old interfaces at version 3.0 (and added warning messages), they have removed back-support at version 3.1.
Cylc is currently sticking with Jinja2 v3.0.x in order to give everyone a chance to adapt to the Jinja2 warning messages. There’s more about the update here:
No, not a blocker. I was just testing to see if I could run an LFRic rose stem with Cylc8, there is no immediate rush for me to get this working. I am happy to wait. Thanks again for all your help Oliver and Tim.