Preserve custom shell for PowerShell scripts#22336
Conversation
|
Hi maintainers, I opened this PR to address #21808 by preserving a user-provided shell when I verified the relevant Windows shell override tests locally: pytest src/integrations/prefect-shell/tests/test_commands_windows.py -k override_shell -vResult: 3 passed. Please let me know if you'd like me to add a more targeted regression test or adjust the implementation. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 018fb02ee0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if self.shell is None and ( | ||
| sys.platform == "win32" or extension == ".ps1" | ||
| ): | ||
| shell = "powershell" |
There was a problem hiding this comment.
Preserve PowerShell exit propagation for custom shells
When a user runs .ps1 commands with a PowerShell-compatible custom shell such as shell="powershell.exe" or shell="pwsh", this branch now skips the auto-PowerShell path, so the later if shell == "powershell" check does not append Exit $LastExitCode. For inputs like ShellOperation(commands=["ping bad-host"], shell="powershell.exe"), the script can terminate normally and Prefect reports success even though the native command failed; Microsoft’s powershell.exe -File docs state successful execution exits 0 unless the script terminates with exit. Please preserve the custom executable name while still treating PowerShell executables as PowerShell for exit-code propagation.
Useful? React with 👍 / 👎.
018fb02 to
0237c16
Compare
|
thanks for working on this @rangampallysonali ! I dug into this because the precedence fix is definitely needed, but the issue example still seems to fail after this PR the remaining problem is that I verified this with a GitHub Actions repro in
The shape of the follow-up fix was: def _split_shell_command(shell: str) -> list[str]:
return shlex.split(shell.lower(), posix=sys.platform != "win32") or [shell.lower()]
def _shell_command(shell: str, temp_file_name: str) -> list[str]:
return [*_split_shell_command(shell), temp_file_name]and then use It is also worth recognizing I had opened #22340 while testing, but I am closing it so this contribution can stay here. Feel free to copy anything useful from that branch/body; the important bit is the Windows repro above and adding a regression test for |
Summary
Fix shell selection logic in
ShellOperation._prep_trigger_commandwhen using PowerShell script extensions (.ps1).Previously, the condition:
could evaluate to
Truewheneverextension == ".ps1", even when a custom shell was explicitly provided. This caused Prefect to override the user-specified shell and force"powershell".The condition has been updated to ensure PowerShell is only selected automatically when no shell has been supplied by the user.
Changes
Changed:
to:
Motivation
This aligns the implementation with the expected behavior described in issue #21808 and preserves user-provided shell values when working with PowerShell scripts.
Testing
Verified that the existing Windows shell override tests continue to pass:
Results: