mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

Conditional syntaxes cause an ERROR(?!) if condition is False #1418

Open guillemrbaiges opened 1 year ago

guillemrbaiges commented 1 year ago

I'm migrating a former Copier (Jinja2) template into Nunjucks. So far I have focused on the following conditionals:

src/
     {% if values.include_deployment %}main.py{% endif %}
     {% if values.include_deployment %}pipeline.py{% endif %}
     {% if not values.include_deployment %}pipeline.py{% endif %}

All the issues I have found while debugging this simple use case:

  1. Without modifying the code above, this example outcomes the following error: EISDIR: illegal operation on a directory, open '/tmp/0eb043fb-1a7a-4c8c-b226-8b5fd818a662/src'
  2. If the not is deleted and values.include_deployment == true, then templating this snippet works as expected
  3. If the not is deleted and values.include_deployment == false, then templating this snippet fails with: Error: EISDIR: illegal operation on a directory, open '/tmp/f9cd3cf9-b493-4af4-8f9a-8101ba5c3fb3/src'
  4. If I add the not to the three conditionals and values.include_deployment == false, then templating this snippet works as expected
  5. If I delete the not and use ... == false the error is the same (EISDIR)
  6. If I change the not for ! it complains about the later being an unrecognized token

Based on your FAQs this should not be a compatibility issue between Jinja2 and Nunjucks. This syntax is the same in both Python and Javascript and, honestly, this is one of the most basic functionalities you expect in a templating engine. What's happening here?