# Cylc 8 with LFRic Rose stems and Jinja2 issues

**URL:** <https://cylc.discourse.group/t/cylc-8-with-lfric-rose-stems-and-jinja2-issues/525>\
**Category:** Cylc 8 Migration\
**Created:** [August 26, 2022, 6:19am UTC](https://cylc.discourse.group/t/cylc-8-with-lfric-rose-stems-and-jinja2-issues/525 "2022-08-26T06:19:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![oliver.sanders](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/oliver.sanders/32/110_2.png) [@oliver.sanders](https://cylc.discourse.group/u/oliver.sanders)\
**Post date:** [August 26, 2022, 12:38pm UTC](https://cylc.discourse.group/t/cylc-8-with-lfric-rose-stems-and-jinja2-issues/525/4 "2022-08-26T12:38:23Z")

</div>

Took a look into this myself,

I tracked the problem down to this line:

```auto
subtree = context.vars['target'][target_dets['platform']]

```

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:

```diff
 @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:

```

---

_[View the full topic](https://cylc.discourse.group/t/cylc-8-with-lfric-rose-stems-and-jinja2-issues/525)._
