jinja2 error in the workflow "template" node #1751

Closed
opened 2026-02-21 17:37:26 -05:00 by yindo · 0 comments
Owner

Originally created by @badbye on GitHub (Apr 3, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Pleas do not modify this template :) and fill in all the required fields.

Dify version

dify-web@0.5.11-fix1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

create a workflow, add a template node with a string variable named var, here is the code:

{% if var == "1" %}
1 
{% else %}
0
{% endif %}

test run, no matter what values assign to var, you will got the following error:
image

Delete the quotes in the template code:

{% if var == 1 %}
1 
{% else %}
0
{% endif %}

It works as "expect", however I was passing a string value, it should not work.

✔️ Expected Behavior

Here is how jinja2 works in Python:

# # the template expression works with string
temp = Template('''{% if var == "1" %} 1 {% else %} 0 {% endif %}''')
print(temp.render(var='1'))
# 1
print(temp.render(var=1))
# 0


# the template expression is able to distinguish between numbers and characters
temp = Template('''{% if var == 1 %} 1 {% else %} 0 {% endif %}''')
print(temp.render(var='1'))
# 0
print(temp.render(var=1))
# 1

Actual Behavior

throw an error:

05, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "", line 1027, in _find_and_load File "", line 1002, in _find_and_load_unlocked File "", line 945, in _find_spec File "", line 1439, in find_spec File "", line 1411, in _get_spec File "", line 1548, in find_spec File "", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' le> File "", line 4, in File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1208, in new File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1105, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "", line 1027, in _find_and_load File "", line 1002, in _find_and_load_unlocked File "", line 945, in _find_spec File "", line 1439, in find_spec File "", line 1411, in _get_spec File "", line 1548, in find_spec File "", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' le> File "", line 4, in File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1208, in new File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1105, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "", line 1027, in _find_and_load File "", line 1002, in _find_and_load_unlocked File "", line 945, in _find_spec File "", line 1439, in find_spec File "", line 1411, in _get_spec File "", line 1548, in find_spec File "", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' error: exit status 255

Originally created by @badbye on GitHub (Apr 3, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Pleas do not modify this template :) and fill in all the required fields. ### Dify version dify-web@0.5.11-fix1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce create a workflow, add a `template` node with a string variable named `var`, here is the code: ``` {% if var == "1" %} 1 {% else %} 0 {% endif %} ``` test run, no matter what values assign to var, you will got the following error: ![image](https://github.com/langgenius/dify/assets/3295865/8d09f1a4-2704-42e3-9f03-bd991cc75d67) Delete the quotes in the template code: ``` {% if var == 1 %} 1 {% else %} 0 {% endif %} ``` It works as "expect", however I was passing a string value, it should not work. ### ✔️ Expected Behavior Here is how jinja2 works in Python: ```python # # the template expression works with string temp = Template('''{% if var == "1" %} 1 {% else %} 0 {% endif %}''') print(temp.render(var='1')) # 1 print(temp.render(var=1)) # 0 # the template expression is able to distinguish between numbers and characters temp = Template('''{% if var == 1 %} 1 {% else %} 0 {% endif %}''') print(temp.render(var='1')) # 0 print(temp.render(var=1)) # 1 ``` ### ❌ Actual Behavior throw an error: > 05, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 945, in _find_spec File "<frozen importlib._bootstrap_external>", line 1439, in find_spec File "<frozen importlib._bootstrap_external>", line 1411, in _get_spec File "<frozen importlib._bootstrap_external>", line 1548, in find_spec File "<frozen importlib._bootstrap_external>", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' le> File "<string>", line 4, in <module> File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1208, in __new__ File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1105, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 945, in _find_spec File "<frozen importlib._bootstrap_external>", line 1439, in find_spec File "<frozen importlib._bootstrap_external>", line 1411, in _get_spec File "<frozen importlib._bootstrap_external>", line 1548, in find_spec File "<frozen importlib._bootstrap_external>", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' le> File "<string>", line 4, in <module> File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1208, in __new__ File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1105, in from_string File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 768, in compile File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 934, in handle_exception File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 945, in _find_spec File "<frozen importlib._bootstrap_external>", line 1439, in find_spec File "<frozen importlib._bootstrap_external>", line 1411, in _get_spec File "<frozen importlib._bootstrap_external>", line 1548, in find_spec File "<frozen importlib._bootstrap_external>", line 1591, in _fill_cache OSError: [Errno 9] Bad file descriptor: '/usr/local/lib/python3.10/site-packages/jinja2' error: exit status 255
yindo added the 🐞 bug🌊 feat:workflow labels 2026-02-21 17:37:26 -05:00
yindo closed this issue 2026-02-21 17:37:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#1751