Repository navigation
Python: fix(functions): validate complex kernel function arguments - #14466
Adil Alperen Çiftci (adilalperenciftci) wants to merge 5 commits into
Conversation
|
Updated the branch to current |
Complex and Union annotations containing commas could skip parameter parsing in gather_function_parameters, allowing raw argument values to reach the kernel function. Validate generic annotations with Pydantic TypeAdapter so malformed values are rejected before invocation. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
… empty Preserve PEP 604 and typing.Union type metadata during kernel function parameter inspection when unions do not contain NoneType. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
TypeAdapter rejected unions that include ordinary Python classes before validating the selected branch, so a valid str or custom instance passed to a parameter annotated Custom | str raised FunctionExecutionException. Configure the adapter with arbitrary_types_allowed and add regressions for the valid primitive, the valid custom instance, and the still-rejected invalid argument. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
fa177a7 to
62f0f42
Compare
|
I rebased the branch onto current main and retained the arbitrary-class union regression coverage. The focused function suites pass 115 tests on Python 3.12, and ruff is clean for the changed files. I also resolved the addressed review thread. |
Ammann Labs (agammann)
left a comment
There was a problem hiding this comment.
Removing the comma guard should validate generic annotations such as dict[str, int], but the new tests only exercise unions. Could the regression suite pass one valid and one invalid value to a function with a dict[str, int] argument? That would cover the previously skipped comma path and the new TypeAdapter branch directly.
Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
|
Added the requested valid and invalid |
Summary
Complex and union annotations containing commas could skip parameter validation in
gather_function_parameters, allowing values with the wrong shape to reach the kernel function. PEP 604 unions also needed their original annotation preserved when non-optional type resolution returned no entries.Changes
TypeAdapter.dict[str, int]inputs, invalid union inputs, valid primitive branches, and valid custom-class instances.Validation