Skip to content

Fix the PSQL tool failing to start psql on Windows - #10725

Closed
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-10714-psql-argv0
Closed

dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-10714-psql-argv0

Conversation

@dpage

@dpage dpage commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10714.

Since #10453 spawned psql directly through pywinpty instead of via cmd.exe, psql has started with an empty argv[0] on Windows and failed with could not find a "" to execute and could not find own program executable. pywinpty passes argv[0] to CreateProcess as the application name, but builds the command line from argv[1:] alone (winpty/ptyprocess.py, the same in 2.0.15 and 3.1.2), so psql never sees its own name. This repeats the executable as the first argument, so that it also leads the command line.

The unit test only checks the arguments passed to spawn, so this still needs a check on Windows that the PSQL tool connects. Whoever does that could also try pywinpty 3.1.2 (#10669) at the same time, watching for psql output only appearing after a keypress, which was the original reason for the 2.0 pin.

Summary by CodeRabbit

  • Bug Fixes
    • Improved psql session startup on Windows by correcting the command-line invocation passed to the terminal process. Environment handling remains unchanged, and no other platform behavior is affected. This update concerns Windows command launching only; it does not change connection settings or add user-facing options.

Since psql has been spawned directly through pywinpty (pgadmin-org#10453), it has
started with an empty argv[0], because pywinpty passes argv[0] to
CreateProcess as the application name but builds the command line from
argv[1:] alone. psql then fails with "could not find own program
executable". Repeat the executable so that it is also the first word of
the command line.

Fixes pgadmin-org#10714
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

On Windows, windows_platform now passes the executable name twice at the start of the PSQL spawn arguments. The EOF-before-exit test checks those arguments and the empty environment.

Changes

Windows PSQL startup

Layer / File(s) Summary
Set and verify Windows spawn arguments
web/pgadmin/tools/psql/__init__.py, web/pgadmin/tools/psql/tests/test_windows_pty_failures.py
windows_platform duplicates the executable name in the spawn arguments and continues to pass the user environment. The EOF-before-exit test expects the duplicated name, database argument, and empty environment.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: kundansable

Merge Risk: Minimal · up to b5bf6

This change repeats the executable name in the PSQL spawn arguments so the PSQL tool can start on Windows. No concrete defect was found. Confirming on Windows that the PSQL tool connects is still recommended before release.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change. The PR fixes the psql tool failing to start on Windows. The raw summary shows the Windows spawn path now repeats the executable as the first argument, which addresses …
Linked Issues check Passed Issue #10714 requires the PSQL Tool to start psql on Windows without the errors 'could not find a "" to execute' and 'could not find own program executable'. The only coding requirement is this startu…
Out of Scope Changes check Passed The reviewed head changes two files. In web/pgadmin/tools/psql/init.py, the change is a targeted edit in windows_platform plus a comment that explains the pywinpty argv[0] behavior and cites #1071…
Full details: Title check

Explanation

The title names the main change. The PR fixes the psql tool failing to start on Windows. The raw summary shows the Windows spawn path now repeats the executable as the first argument, which addresses that startup failure. The title is specific and matches the linked issue and the PR objectives.

Full details: Linked Issues check

Explanation

Issue #10714 requires the PSQL Tool to start psql on Windows without the errors 'could not find a "" to execute' and 'could not find own program executable'. The only coding requirement is this startup fix. The reviewed head changes web/pgadmin/tools/psql/init.py in windows_platform. It now calls PtyProcess.spawn with [connection_data[0]] + list(connection_data), so the executable is also argv[0] in the command line. The previous code passed connection_data unchanged. The issue error text matches an empty argv[0]. The PR description states that pywinpty uses argv[0] only as the application name and builds the command line from argv[1:]. This change addresses that cause directly. Limits: the pywinpty behavior is external and was not verified in this repository. The test file diff could not be read, so the summary is the only evidence for its assertion. No Windows runtime run is present. The PR description itself says a Windows connection check is still needed. The fix is consistent with the reported failure, so the requirement is met on the evidence available.

Full details: Out of Scope Changes check

Explanation

The reviewed head changes two files. In web/pgadmin/tools/psql/init.py, the change is a targeted edit in windows_platform plus a comment that explains the pywinpty argv[0] behavior and cites #10714. It directly implements the linked issue. In web/pgadmin/tools/psql/tests/test_windows_pty_failures.py, the summary reports a four-line addition. It asserts that spawn receives ['psql', 'psql', 'dbname=postgres'] with an empty environment. This is a supporting test for the same change. No unrelated refactoring, documentation, or feature work is described. The PR description's suggested pywinpty 3.1.2 trial is not part of the diff. The test file diff could not be read directly, so this verdict relies on the summary for that file. That file's content is described as supporting and narrow.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 758d51d and b5bf60b.

Files selected for processing: 2
  • web/pgadmin/tools/psql/__init__.py
  • web/pgadmin/tools/psql/tests/test_windows_pty_failures.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@dpage

dpage commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged as df554c7.

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.

PSQL tool not working as expected on pgAdmin 9.19 -

1 participant