Skip to content

Fix selection-filter panics when no test is supplied #22

Closed

Description

@qoke

select, reject, selectattr, and rejectattr support using truthiness when no explicit test is supplied. Those calls can currently panic while extracting optional test arguments.

{{ [0, 1, 2] | select | list }}
{{ [0, 1, 2] | reject | list }}
{{ [{'enabled': true}, {'enabled': false}] | selectattr('enabled') | list | length }}
{{ [{'enabled': true}, {'enabled': false}] | rejectattr('enabled') | list | length }}

Expected Python Jinja2 output:

[1, 2]
[0]
1
1

The implementation slices past the available arguments before the default truthiness behaviour gets a chance to run.

I’m raising a small PR to check the argument count before slicing and use an empty argument list when no additional test arguments are present. Explicit tests and their arguments will continue to pass through unchanged.

I’ll attach the PR here shortly, with regression tests for all four default-test forms.

Activity

  1. ardan-bkennedy commented on Oct 26, 2026

    @ardan-bkennedy
    Contributor

    Resolved in #34 and published in v1.11.0, with corresponding regression tests covering the reported problem. Thank you, @qoke, for the report and suggested solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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