-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Ensure -PipelineVariable is set for all output from script cmdlets #12766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure -PipelineVariable is set for all output from script cmdlets #12766
Conversation
|
Codefactor and Codacy issues are with untouched code areas / not applicable. 🙂 |
1ef6559 to
3a12833
Compare
|
I think this falls into a bucket 3 breaking change and I think we should take the change. |
rjmholt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me
|
@PowerShell/powershell-committee reviewed this, we agree that the previous behavior was broken and falls under bucket 3 as a breaking change, so approve the intended new behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm a little concerned that there isn't enough validation. Can you think of additional edges here that we should be poking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are probably numerous odd cases where this might crop up, but I can't think of any that are really different from the test case here. At the very least, this does cover the test case that we know is currently broken.
I've not seen any other cases crop up myself, nor had someone drop in the community channels with an issue that came down to this. I suspect that that's more due to -PipelineVariable being a bit more of a niche concept from the start, though.
Without knowing for sure about other broken cases, the best I can do is test a few other cases with multiple script cmdlets and various mixes of script / compiled cmdlets to see if the logic breaks down anywhere.
The only real unknown where I don't know what to actually expect is what is meant to happen if multiple cmdlets in the same pipeline declare the same pipeline variable. I'm not sure the expected behaviour there is even recorded anywhere. Best guess - the nearest command to the variable's usage will have its output in there at any given point...
If anyone else has cases they know to be broken / likely to break, I'd appreciate having those as well.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@JamesWTruher can you respond to @vexx32 |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@JamesWTruher please update your review / let me know if you have additional cases to cover with tests. Thanks! 💖 |
JamesWTruher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can always add more validation if we find additional cases.
Previously, for script functions -PipelineVariable would only take effect for the duration of the first output, and then stopped working. Borrowed some code from the compiled cmdlets' implementation which has always worked just fine. This appears to resolve the issue. :bug: Fix NRE with dynamicparam Dynamicparam blocks also do enter/exit scope, but seem to lack a state. Workaround is to check for null state and fallback to previous behaviour for dynamicparam blocks. This should not cause any issues since output can't be passed from dynamicparam, so -PipelineVariable can't be set from this block.
581f2c5 to
7b0a58b
Compare
|
@TravisEz13 is there anything left pending here? 🙂 |
|
Open PRs should not be assigned to milestone, so they are not assigned to the wrong milestone after they are merged. For backport consideration, use a |
|
Merged this so we can include it in the next preview in order to validate it better |
|
🎉 Handy links: |
PR Summary
Previously, -PipelineVariable was only set for the first occurence of output from a script cmdlet. This change borrows some code from the handling for compiled commands to ensure -PipelineVariable is always set correctly and should behave as expected even for script cmdlets.
PR Context
This PR resolves #10932, see this issue for further discussion.
We will need to document the bugged behaviour for downlevel versions of PowerShell in docs so that users are aware. Most folks probably won't have noticed it, but people may still run into it from time to time on downlevel versions.
@SteveL-MSFT I'm not 100% sure, but this feels like the kind of fix y'all might want in a servicing release for 7.0. 🙂
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.