Repository navigation
jinja : fix select and selectattr argument handling - #31059
Conversation
|
/bot review |
Automated code reviewReview of PR #31059 - jinja: fix select and selectattr argument handlingI reviewed the diff statically, tracing Verdict: the fix is correct and matches Jinja2 semantics. The old count-based branches conflated
Minor points, none blocking: (point 1) (point 2) The static function is still named (point 3) The tests cover the new happy paths well, but not the new error path. Consider adding one test asserting that (point 4) Worth being aware (no change requested): the old 3-arg form Style checks pass: ASCII only, comments concise and useful, tests added to the existing file/function following existing patterns, no unrelated changes, commit message fine (no This review was generated automatically by pi coding agent using |
CISC
left a comment
There was a problem hiding this comment.
Nice catch, thank you!
Please address bot points 1-3.
|
Thanks for the quick review! I implemented all three, but slightly differed on the test suggestion. I kept the selectattr case and added select('nosuchtest'), since that's the case that used to return an empty list silently. Selectattr already raised before this PR, so the test also checks that the error names 'nosuchtest' (the old code reported 'x'). |
It's too elaborate and specific, can I suggest that you instead just use an attr with the same name as a test? The concern isn't really the error message, but that is uses the right arg. |
|
Oooooh I see now. I simplified the test a lot and should be a lot closer to what your suggesting / neater. Thanks so much for the help! Let me know if you need anything else from me. |
* jinja : fix select and selectattr argument handling * jinja : address review feedback * jinja : Simplified test attr
* jinja : fix select and selectattr argument handling * jinja : address review feedback * jinja : Simplified test attr
Overview
Fixes #31057
The Functionary v3.2 chat template fails with
selectattr: unknown test 'type'when a tool parameter usesoneOf. The shared filter implementation interprets arguments by count, soselectattr('type', 'defined')treats the attribute name as the test name.Each registration now declares whether it reads an attr through the
lookup_attrtemplate parameter. With the input array at position 0, the test name is at position 1 forselect/rejectand position 2 forselectattr/rejectattr. One loop replaces the three count-based branches and forwards all remaining template args to the test.selectattr('type', 'defined')now selects items with a definedtypeattr, allowing the template to renderoneOfparameters.This has two side effects:
select('nonexistent')used to return an empty list silently. It now raisesselect: unknown test 'nonexistent', matching Jinja2.select/rejectused to error. They now keep truthy or falsy items (respectively).Additional information
N/A
Requirements