Repository navigation
fix(core): reject unsupported dictionary unpacking in safe_expr - #939
Conversation
Reject ast.Dict unpacking at validation time so unsupported expressions do not silently evaluate using a None key. Cover nested and short-circuited unpacking, and preserve ordinary dictionary literals with None keys. Generated-by: OpenAI Codex
sivakumar-mahalingam
left a comment
There was a problem hiding this comment.
Could we include the original reported reproducer in the regression cases as well?
For example, bool({**{}}) is one of the concrete failures described in this PR, but the current parameterized test only exercises dictionary unpacking directly or through list/boolean nesting. Adding the exact reproducer would also verify that unpacking is rejected when the dictionary appears as an argument to an otherwise allowed builtin call.
It may also be worth including the membership case ('allowed' in {**mapping}) mentioned in the description, so both previously incorrect evaluation paths are explicitly protected against regression.
elijahbenizzy
left a comment
There was a problem hiding this comment.
LGTM, right place for the check. After #947 lands the k-is-not-None fallback in _eval_Dict becomes unreachable; I'll drop it there. Elijah
Condition.safe_expr("bool({**{}})")currently returns true: dictionary unpacking passes validation, but the interpreter treats its AST sentinel as a literalNonekey. Similarly, a membership condition such as'allowed' in {**mapping}silently returns false even whenmappingcontains that key.Changes
Reject unsupported dictionary unpacking when constructing the condition, matching the existing rejection of other unpacking forms. Document the restriction and cover plain, mixed, repeated, nested, and short-circuited unpacking, plus a valid literal
Nonekey.How I tested this
python -m pytest tests/core/test_action.py -q: 160 passed.tests/corerun: 402 passed; four existing graph-rendering tests failed because the local Windows environment has no Graphvizdotexecutable.git diff --checkalso passed.Notes
Prepared with OpenAI Codex assistance; the regression and broader test results above were run locally. The commit includes a
Generated-bytrailer.Checklist