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:
def get_target_property(context, target_dets, prop_path=None, compiler=None):
if prop_path is not None:
path_parts = prop_path.split('.')
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.
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.