Skip to content

fix: guard PasswordExec against None host/port/username - #10326

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10237-passexec-service-only
Open

fix: guard PasswordExec against None host/port/username#10326
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10237-passexec-service-only

Conversation

@dpage

@dpage dpage commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Service-only connections (pg_service.conf with host/port/username left blank) crashed a per-server Password Exec Command with TypeError: replace() argument 2 must be str, not None, because PasswordExec.get() passed None straight into str.replace().
  • %HOSTNAME%, %PORT% and %USERNAME% placeholders now fall back to an empty string when the corresponding attribute is unset.

Test plan

  • Added web/pgadmin/utils/tests/test_passexec.py, verified it fails against the pre-fix code and passes with the fix.
  • pycodestyle clean on both changed files.

Closes #10237

Summary by CodeRabbit

  • Bug Fixes

    • Improved password retrieval for Service-only connections when host, port, or username details are unavailable.
    • Ensured missing connection values are handled safely while preserving username formatting where applicable.
  • Tests

    • Added regression coverage for password retrieval with incomplete connection details.

Service-only connections (pg_service.conf) leave host, port and username
unset, so a per-server Password Exec Command crashed in get() with
TypeError: replace() argument 2 must be str, not None. Fall back to an
empty string for each unset placeholder instead.

Closes pgadmin-org#10237
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6fecf948-5bdc-46e1-a39b-d5a4931dec9b

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebefaf and a3ce790.

📒 Files selected for processing (2)
  • web/pgadmin/utils/passexec.py
  • web/pgadmin/utils/tests/test_passexec.py

Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review.


Walkthrough

PasswordExec.get() now handles unset host, port, and username values during command substitution. A regression test covers service-only connections and verifies successful password retrieval.

Changes

Password Exec service-only connections

Layer / File(s) Summary
Safe placeholder substitution and regression coverage
web/pgadmin/utils/passexec.py, web/pgadmin/utils/tests/test_passexec.py
Missing host, port, and username values become empty command substitutions. Existing username identifier quoting remains active for set usernames. The regression test verifies command execution and password output for a service-only connection.

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

Merge Risk: ⚪ Minimal · up to a3ce7

The change safely handles unset host, port, and username values by substituting empty strings; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and concisely describes the fix for unset Password Exec connection values.
Linked Issues check ✅ Passed The changes replace unset host, port, and username values with empty strings and add regression coverage for issue #10237.
Out of Scope Changes check ✅ Passed The code and test changes directly support the linked issue and stated objectives without unrelated modifications.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

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.

replace() argument 2 must be str, not None when using per-server Password Exec Command with Service field (pg_service.conf)

1 participant