Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

PaulHigin
Copy link
Contributor

@PaulHigin PaulHigin commented Feb 11, 2020

PR Summary

This fixes a bug in ForEach-Object -Parallel where a using variable in a nested ForEach-Object -Parallel throws an error even when the variable is defined in the correct scope (Issue #11817).

PR Context

This error was occurring because, when ForEach-Object -Parallel was assembling the user variable map, it was searching all nested scriptblocks within the ForEach scriptblock, with the result of finding nested using variables where the variable had not yet been defined. Since the nested scriptblock using variable had not been defined in the current scope, a mapping error was thrown.

Fix is to change the using variable map function to not search nested scriptblocks in the ForEach -Parallel case. This way foreach -parallel using variable mapping is always performed only for the current scope.

Many thanks to @mklement0 for pointing out the fix.

PR Checklist

@ghost ghost assigned anmenaga Feb 11, 2020
@PaulHigin PaulHigin requested a review from daxian-dbw February 11, 2020 18:07
@vexx32
Copy link
Collaborator

vexx32 commented Feb 12, 2020

@PaulHigin would this fix also affect the use of nested iterations of Start-ThreadJob and similar $using: variable usage there?

@PaulHigin
Copy link
Contributor Author

@vexx32 No, ThreadJob will also need to change. Please create an issue for it.

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Feb 12, 2020
@PaulHigin PaulHigin changed the title Fix using variable error for nested foreach parallel [WIP] Fix using variable error for nested foreach parallel Feb 13, 2020
@vexx32
Copy link
Collaborator

vexx32 commented Feb 14, 2020

Just double checked it, and looks like Start-ThreadJob doesn't exhibit the same issue, interestingly enough. 🎉

@PrzemyslawKlys
Copy link

Will this be added to RC3?

@daxian-dbw
Copy link
Member

@PrzemyslawKlys I don't think so, as the RC3 is already locked down and we have a very high bar for GA. But this fix will be included in a servicing release later.

@ghost
Copy link

ghost commented May 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@PrzemyslawKlys
Copy link

What is the status of this PR?

@PaulHigin
Copy link
Contributor Author

AFAIK there is no reason not to take this PR. @daxian-dbw can we include this in the next preview release?

@iSazonov
Copy link
Collaborator

iSazonov commented Jan 5, 2021

@PaulHigin Please rebase to pass CIs.

@ghost ghost removed the Review - Needed The PR is being reviewed label Jan 5, 2021
@PaulHigin
Copy link
Contributor Author

Closing this PR since it is so old, and created a new one (#14548)

@PaulHigin PaulHigin closed this Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants