Validate PsrpOperator parameters after rendering#70347
Open
1fanwang wants to merge 6 commits into
Open
Conversation
1fanwang
requested review from
amoghrajesh,
ashb,
bugraoz93,
gopidesupavan,
jason810496,
jscheffl and
potiuk
as code owners
July 23, 2026 23:24
command, powershell, cmdlet, arguments and parameters are template fields, rendered after __init__ runs. The constructor validated their combination and derived task_id from cmdlet, all reading the un-rendered Jinja expressions. Move the validation into execute(), which runs after rendering. This drops the cmdlet-derived task_id default (a construction-time read of a template field that cannot move): task_id must now be passed explicitly when using cmdlet. related: apache#70296 Signed-off-by: 1fanwang <1fannnw@gmail.com>
1fanwang
marked this pull request as draft
July 24, 2026 05:47
Signed-off-by: 1fanwang <1fannnw@gmail.com>
1fanwang
marked this pull request as ready for review
July 24, 2026 06:23
Signed-off-by: 1fanwang <1fannnw@gmail.com> # Conflicts: # scripts/ci/prek/validate_operators_init_exemptions.txt
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
command is a template field, so validating it in __init__ checked the raw Jinja expression, not the rendered value. Add a test that renders a command resolving to an empty string, then executes: it fails on the pre-fix source (the empty command slips past __init__ and reaches execution) and passes with validation in execute(). Signed-off-by: 1fanwang <1fannnw@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
command,powershell,cmdlet,argumentsandparametersare template fields, so they are rendered after__init__runs. The constructor validated their combination (exactly one of command/powershell/cmdlet; arguments/parameters only with powershell/cmdlet) and derivedtask_idfromcmdlet— all reading the un-rendered Jinja expressions. Move the validation intoexecute(), which runs after rendering.Breaking change (flagged for maintainers): this drops the
cmdlet-derivedtask_iddefault. That default read thecmdlettemplate field at construction, beforesuper().__init__, andtask_idis identity — so it is the one piece that can't move toexecute(). Passtask_idexplicitly when usingcmdlet. If you'd rather keep the convenience, the alternative is to leavePsrpOperatoron the exemption list until the check can sanction atask_id-from-template default; I went with the removal to clear the entry, but happy to revert that part.related: #70296
Testing Done
test_no_command_or_powershellnow asserts theValueErrorsurfaces fromexecute(); it fails on the pre-fix source (the constructor raised first) and passes after. Droppedtest_cmdlet_task_id_default(behaviour removed) and passedtask_idexplicitly in the twosecurestringtests.test_psrp.py: 33 passed.validate_operators_init.pyon the operator exits 0.Was generative AI tooling used to co-author this PR?
Generated-by: GitHub Copilot CLI following the guidelines