Skip to content

Nested macro functions with same name functions differently in Jinjava vs Jinja #868

@jasmith-hs

Description

@jasmith-hs

The output of:

{% macro foo() -%}
{% macro foo() -%}
1
{%- endmacro %}
{{ foo() }} 2
{%- endmacro %}
{{ foo() }}
{{ foo() }}

Should be:

1 2

1 2

However, in Jinjava, the output is:

1 2
1

This is because macro functions defined inside of a macro function will override existing macro functions, rather than defining macro functions that exist solely within that scope.

This problem extends beyond just overriding macro functions with the same name. Macro functions defined inside of another macro function should not be usable outside of their defined scope. For example:

{% macro foo() -%}
{% macro bar() -%}
1
{%- endmacro %}
{{ bar() }} 2
{%- endmacro %}
{{ foo() }}
{{ bar() }}

The final bar() should not be calling anything, but the result in Jinjava is:

1 2
1

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