Taragolis commented on issue #34394:
URL: https://github.com/apache/airflow/issues/34394#issuecomment-1721895692

   > I appreciate the PR with change of documentation, but I still see it as an 
inconsistency that
   {{ var.json.somekey.somecontent } works
   and
   {{ var.json.get('somekey.somecontent', false)
   Doesn’t. 
   
   In this cases `var.json` is references to object (dictionary) and other part 
it is the way how you could access `__getitem__` in [Jinja 
Variable](https://jinja.palletsprojects.com/en/3.1.x/templates/#variables). 
   
   Some native Jinja templates sample
   
   ```python
   import jinja2
   environment = jinja2.Environment()
   
   var = {"a": {"b": {"c": 1 }}}
   
   template = environment.from_string("Sample a.b.c = {{ awesome_var.a.b.c }}")
   print(template.render(awesome_var=var))
   # Sample a.b.c = 1
   
   template = environment.from_string("Sample ['a']['b']['c'] = {{ 
awesome_var['a']['b']['c'] }}")
   print(template.render(awesome_var=var))
   # Sample ['a']['b']['c'] = 1
   
   template = environment.from_string("Sample mixin = {{ 
awesome_var.get('a')['b'].c }}")
   print(template.render(awesome_var=var))
   # Sample mixin = 1
   
   template = environment.from_string("Sample by key = {{ 
awesome_var.get('a.b.c', 'Foo') }}")
   print(template.render(awesome_var=var))
   # Sample mixin = Foo
   
   template = environment.from_string("Sample by pseudo json-path = {{ 
awesome_var.get('a.b.c') }}")
   print(template.render(awesome_var=var))
   # Sample by pseudo json-path = None
   ```
   
   AFAIK `var.json.name` it is specific class with own `get` method, which 
close to regular nested dict and it is work by the same way as dictionary works 
in Jinja Templates, so this behaviour pretty consistent with Jinja


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to