nodejs/node · error · FilterArgumentError

Unexpected keyword argument %r

Error message

Unexpected keyword argument %r

What it means

prepare_map parses arguments for the map filter. When called as {{ seq|map(attribute='x') }}, the only accepted keyword is 'attribute'. If 'attribute' was already consumed and any extra keyword arguments remain, they are unrecognized and Jinja2 raises FilterArgumentError naming the first leftover kwarg.

Source

Thrown at tools/inspector_protocol/jinja2/filters.py:1088

    .. versionadded:: 2.9
    """
    policies = eval_ctx.environment.policies
    dumper = policies['json.dumps_function']
    options = policies['json.dumps_kwargs']
    if indent is not None:
        options = dict(options)
        options['indent'] = indent
    return htmlsafe_json_dumps(value, dumper=dumper, **options)


def prepare_map(args, kwargs):
    context = args[0]
    seq = args[1]

    if len(args) == 2 and 'attribute' in kwargs:
        attribute = kwargs.pop('attribute')
        if kwargs:
            raise FilterArgumentError('Unexpected keyword argument %r' %
                next(iter(kwargs)))
        func = make_attrgetter(context.environment, attribute)
    else:
        try:
            name = args[2]
            args = args[3:]
        except LookupError:
            raise FilterArgumentError('map requires a filter argument')
        func = lambda item: context.environment.call_filter(
            name, item, args, kwargs, context=context)

    return seq, func


def prepare_select_or_reject(args, kwargs, modfunc, lookup_attr):
    context = args[0]
    seq = args[1]
    if lookup_attr:

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Pass only the 'attribute' keyword to the attribute form: {{ seq|map(attribute='name') }}.
  2. If you need a transformation with options, use the filter-name form {{ seq|map('filter_name', *args) }} or chain filters after map.

Example fix

{# before #}
{{ users|map(attribute='name', default='anon') }}

{# after #}
{{ users|map(attribute='name') }}
Defensive patterns

Strategy: validation

Validate before calling

def validate_map_kwargs(kwargs):
    extra = set(kwargs) - {'attribute'}
    if extra:
        raise ValueError('map: unexpected keyword argument(s) %r' % (sorted(extra),))

Type guard

def is_map_kwarg(name: str) -> bool:
    return name == 'attribute'

Try / catch

from jinja2.exceptions import FilterArgumentError
try:
    out = env.call_filter('map', seq, args=(), kwargs=kwargs)
except FilterArgumentError:
    out = env.call_filter('map', seq, args=(), kwargs={'attribute': kwargs['attribute']})

Prevention

When it happens

Trigger: Calling {{ seq|map(attribute='name', default='x') }} or any map invocation that passes 'attribute' plus one or more additional keyword arguments.

Common situations: Assuming map(attribute=...) accepts filter options like 'default'; typos in the keyword name (e.g. attr=, field=).

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/c9ea00e80a6d3e68. Report an issue: GitHub.