Skip to content

Custom async filters not awaited for constant inputs #1279

@radcliffkey

Description

@radcliffkey

In async mode, if I create a custom async filter, it works correctly when called on data passed by render, but not on constants in the template itself. See code below.


Expected Behavior

print

Hello test1
Hello test2

Actual Behavior

print

<coroutine object myfilter at 0x7f89c7a393c0>
Hello test2

Template Code

import asyncio
import jinja2


async def myfilter(instr):
    return f'Hello {instr}'


async def main():

    env = jinja2.Environment(enable_async=True)
    env.filters['myfilter'] = myfilter

    tmpl = env.from_string('{{"test1"|myfilter}}\n{{x|myfilter}}')

    text = await tmpl.render_async(x='test2')
    print(text)


if __name__ == '__main__':
    asyncio.run(main())

Your Environment

  • Python version: 3.8.2
  • Jinja version: 2.11.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions