Skip to content
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

Loop properties revindex and revindex0 still wrong in Jinja2 2.10 #794

Closed
unusual-thoughts opened this issue Jan 8, 2018 · 5 comments · Fixed by #993
Closed

Loop properties revindex and revindex0 still wrong in Jinja2 2.10 #794

unusual-thoughts opened this issue Jan 8, 2018 · 5 comments · Fixed by #993
Milestone

Comments

@unusual-thoughts
Copy link

@unusual-thoughts unusual-thoughts commented Jan 8, 2018

Expected Behavior

loop.revindex should be 1 when using a reversed iterator of length 1

jinja2.Template("{% for i in lst|reverse %}{{ loop.revindex }}:{{ i }}, {% endfor %}")
      .render(lst=[10])

should print out: '1:10, '

Actual Behavior

The index of the only iteration is set to 2

jinja2.Template("{% for i in lst|reverse %}{{ loop.revindex }}:{{ i }}, {% endfor %}")
      .render(lst=[10])

prints out: '2:10, '

However:

jinja2.Template("{% for i in lst|reverse %}{{ loop.revindex }}:{{ i }}, {% endfor %}")
      .render(lst=[10, 11])

correctly prints out: '2:11, 1:10, '

Template Code

{% for i in lst|reverse %}{{ loop.revindex }}:{{ i }}, {% endfor %}

Your Environment

  • Python version: 3.6.4
  • Jinja version: 2.10
@unusual-thoughts

This comment has been minimized.

Copy link
Author

@unusual-thoughts unusual-thoughts commented Jan 9, 2018

Related to #244 and 4eb30f1

@FreddieChopin

This comment has been minimized.

Copy link

@FreddieChopin FreddieChopin commented Jan 19, 2018

Also related to #751

@pallets pallets deleted a comment from asenov Feb 13, 2018
@pallets pallets deleted a comment from wuwentao2000 Dec 14, 2018
@aayushuppal

This comment has been minimized.

Copy link
Contributor

@aayushuppal aayushuppal commented May 6, 2019

working on this as part of pycon pallets sprint.

@markroth8

This comment has been minimized.

Copy link
Contributor

@markroth8 markroth8 commented May 31, 2019

Also seems related to #459

@aayushuppal

This comment has been minimized.

Copy link
Contributor

@aayushuppal aayushuppal commented Jun 1, 2019

Should be fixed in #993

@davidism davidism added this to the 2.11.0 milestone Sep 26, 2019
davidism added a commit that referenced this issue Oct 14, 2019
Fix for Loop properties revindex and revindex0 still wrong in Jinja2 2.10 #794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.