nodejs/node · error · FilterArgumentError

map requires a filter argument

Error message

map requires a filter argument

What it means

prepare_map requires the map filter to be told what to do: either an 'attribute' keyword or a positional filter name (args[2]). If neither is supplied (args has only context and seq, and no 'attribute' kwarg), the lookup for args[2] raises LookupError which Jinja2 converts to FilterArgumentError.

Source

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

    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:
        try:
            attr = args[2]
        except LookupError:
            raise FilterArgumentError('Missing parameter for attribute name')
        transfunc = make_attrgetter(context.environment, attr)
        off = 1
    else:
        off = 0

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Provide an attribute: {{ users|map(attribute='email') }}.
  2. Or provide a filter name: {{ items|map('upper') }} or {{ items|map('round', 2) }}.

Example fix

{# before #}
{{ items|map }}

{# after #}
{{ items|map('upper') }}
Defensive patterns

Strategy: validation

Validate before calling

def require_map_argument(attribute=None, filter_name=None, args=()):
    if attribute is None and filter_name is None:
        raise ValueError('map requires an attribute or a filter name')
    return {'attribute': attribute} if attribute else (filter_name,) + tuple(args)

Type guard

def map_has_argument(attribute, filter_name) -> bool:
    return attribute is not None or filter_name is not None

Try / catch

from jinja2.exceptions import FilterArgumentError
try:
    out = env.call_filter('map', seq, args=(name,))
except FilterArgumentError:
    out = seq  # or apply a sensible default filter

Prevention

When it happens

Trigger: Calling {{ seq|map }} with no argument at all, e.g. {{ items|map }}.

Common situations: Forgetting the attribute or filter argument; building the filter call dynamically and dropping the argument.

Related errors


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