Skip to content

macro doesn't work in async mode if autoescape is enabled #671

@mohd-akram

Description

@mohd-akram

Expected Behavior

The macro call should render correctly.

Actual Behavior

The macro call is rendered as a coroutine object repr (<coroutine object macro at 0x10ce50728>).

Python Code

import asyncio

from jinja2 import Template

loop = asyncio.get_event_loop()

async def main():
    print(await render())

async def render():
    t = Template('{% macro foo(x) %}{{ x }}{% endmacro %}{{ foo(42) }}',
                 enable_async=True, autoescape=True)
    return await t.render_async()

loop.run_until_complete(main())

Full Traceback

/Users/mohamed/.virtualenvs/item.tf/lib/python3.6/site-packages/jinja2/runtime.py:501: RuntimeWarning: coroutine 'macro' was never awaited
  rv = Markup(rv)

Your Environment

  • Python version: 3.6
  • Jinja version: 2.9.4

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