Skip to content

Jinja2 2.9 introduces change with free variables in loops that breaks Lektor #649

@freakboy3742

Description

@freakboy3742

Using Lektor 2.3; If you have a project with a sitemap (using the template suggested by the Lektor docs):

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  {%- for page in [site.root] if page != this recursive %}
  <url><loc>{{ page|url(external=true) }}</loc></url>
  {{- loop(page.children) }}
  {%- endfor %}
</urlset>

and you have jinja2 2.9 - 2.9.3, in your environment, you get a build error:

(lektor) hammer:pybee.org rkm$ lektor build
Started build
U ar_AR/sitemap.xml
E ar_AR/sitemap.xml (NameError: free variable 'l_1_this' referenced before assignment in enclosing scope)
U sitemap.xml
E sitemap.xml (NameError: free variable 'l_1_this' referenced before assignment in enclosing scope)
U pt_BR/sitemap.xml
E pt_BR/sitemap.xml (NameError: free variable 'l_1_this' referenced before assignment in enclosing scope)
U zh_TW/sitemap.xml
E zh_TW/sitemap.xml (NameError: free variable 'l_1_this' referenced before assignment in enclosing scope)

Downgrading to Jinja2 2.8.1 seems to resolve the problem.

Reporting there because it would seem to be a regression in Jinja2; however, it's also been reported as lektor/lektor#343 in case it's a usage error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions