Skip to content

Filters decorated with @async_variant are not pickleable  #1612

@dairiki

Description

@dairiki

The jinja2.async_utils.async_variant decorator puts the wrong __name__ and __qualname__ on the decorated function. One result of this is that functions which it decorates are not pickleable.

Here's a doctest script which illustrates the issue.

>>> import pickle
>>> import jinja2.filters

>>> pickle.dumps(jinja2.filters.do_first)
Traceback (most recent call last):
    ...
_pickle.PicklingError: Can't pickle <function sync_do_first at 0x...>: it's not the same object as jinja2.filters.sync_do_first

# Here's the crux:
>>> jinja2.filters.do_first.__name__
'sync_do_first'

Environment:

  • Python version: 3.10 — but I don't think that's important
  • Jinja version: git main (09907ef) — but I think this affects all versions >= 3

I will submit a PR with one possible fix shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions