-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: can't reuse a variable name in a {% for %} loop #640
Comments
Please include a self-contained example that produces this error. |
Okay, I'm trying to write a test now. Wasn't sure if the bug would be obvious given the traceback. |
I think the issue is the construct |
Here's a test: diff --git a/tests/test_core_tags.py b/tests/test_core_tags.py
index 0438008..6cc7dac 100644
--- a/tests/test_core_tags.py
+++ b/tests/test_core_tags.py
@@ -22,6 +22,10 @@ def env_trim():
@pytest.mark.for_loop
class TestForLoop(object):
+ def test_simple_reuse(self, env):
+ tmpl = env.from_string('{% for item in item %}{{ item }}{% endfor %}')
+ assert tmpl.render(item=list(range(10))) == '0123456789'
+
def test_simple(self, env):
tmpl = env.from_string('{% for item in seq %}{{ item }}{% endfor %}')
assert tmpl.render(seq=list(range(10))) == '0123456789' It errors out with |
While this looks a lot like a bug that should be fixed, is it really a good idea to write such code? Especially considering that while Jinja (probably) gets the scoping right, Python itself doesn't (since it has no block scope):
|
I'm a maintainer of Django and don't have much experience with Jinja2 (and didn't write the template). In our case, I'm not sure what the alternative is: |
Kept the build green until a regression is fixed: pallets/jinja#640
Hi, I bisected the introduction of some failures in Django's test suite to 1205e64:
Let me know if I can help or provide additional info.
The text was updated successfully, but these errors were encountered: