Skip to content

Cleaner error message when the server is not installed - closes #1031 - #1396

Open
fizyk wants to merge 2 commits into
mainfrom
issue-1031
Open

Cleaner error message when the server is not installed - closes #1031#1396
fizyk wants to merge 2 commits into
mainfrom
issue-1031

Conversation

@fizyk

@fizyk fizyk commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Improved cross-platform PostgreSQL executable discovery.
    • Validates configured and discovered pg_ctl paths before use.
    • Provides clearer guidance when executables are missing, inaccessible or fail to run.
    • Handles broken pg_config commands consistently, including permission and subprocess errors.
  • Documentation

    • Documented executable lookup order and failure diagnostics.
    • Clarified that postgresql_proc requires local server binaries; externally managed or containerised servers can use postgresql_noproc.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralises PostgreSQL executable discovery. It validates configured and discovered paths, reports pg_config failures, updates executor error handling, adds coverage, and documents server requirements.

Changes

PostgreSQL executable discovery

Layer / File(s) Summary
Executable failure diagnostics
pytest_postgresql/exceptions.py
ExecutableMissingException now reports checked paths, unusable pg_config causes, missing pg_ctl, and remediation guidance.
Executable resolution and validation
pytest_postgresql/factories/_pg.py, pytest_postgresql/factories/process.py, pytest_postgresql/executor.py
pg_ctl resolution checks explicit, configured, and pg_config --bindir paths. Platform-specific names and executable validation are applied. Executor version errors now include the original OSError.
Discovery and integration validation
tests/test_pg_exe.py, tests/test_executor.py
Tests cover precedence, platform names, permissions, client-only installations, pg_config failures, diagnostics, whitespace handling, and the relocated discovery helper.
Discovery and server requirement documentation
README.rst, newsfragments/1031.*.rst
The documentation describes the lookup order, failure details, and requirements for postgresql_proc and postgresql_noproc.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant _pg_exe
  participant _pg_bindir
  participant pg_config
  participant FileSystem
  participant ExecutableMissingException
  _pg_exe->>_pg_bindir: Query pg_config --bindir
  _pg_bindir->>pg_config: Run pg_config --bindir
  pg_config-->>_pg_bindir: Return trimmed binary directory
  _pg_exe->>FileSystem: Check platform-specific pg_ctl names
  FileSystem-->>_pg_exe: Return executable or missing result
  _pg_exe->>ExecutableMissingException: Report checked locations on failure
Loading

Suggested reviewers: tboy1337

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: improving the error message shown when PostgreSQL server executables are not installed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Newsfragment Check ✅ Passed The PR includes newsfragments/1031.bugfix.rst and 1031.docs.rst. Both types are valid in pyproject.toml, and the filenames match the issue-number format.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-1031

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.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.46154% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pytest_postgresql/executor.py 0.00% 1 Missing ⚠️
pytest_postgresql/factories/_pg.py 97.22% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pytest_postgresql/factories/process.py`:
- Around line 64-86: Update _pg_ctl_missing_message so the bindir=None branch
only states that pg_config could not be used to locate PostgreSQL binaries,
without claiming that no PostgreSQL installation exists. Preserve the existing
message for a successfully reported bindir and the remainder of the remediation
guidance.

In `@tests/test_pg_exe.py`:
- Around line 113-120: Update the error parameter values in the
pytest.mark.parametrize declaration to use a list instead of a tuple, preserving
the existing FileNotFoundError, PermissionError, and CalledProcessError cases so
the module satisfies Ruff PT007.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bc493594-a1e4-4b48-803b-fde21c02ade6

📥 Commits

Reviewing files that changed from the base of the PR and between 10f708e and b2b0ed9.

📒 Files selected for processing (7)
  • README.rst
  • newsfragments/1031.bugfix.rst
  • newsfragments/1031.docs.rst
  • pytest_postgresql/executor.py
  • pytest_postgresql/factories/process.py
  • tests/test_executor.py
  • tests/test_pg_exe.py

Comment thread pytest_postgresql/factories/process.py Outdated
Comment thread tests/test_pg_exe.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pytest_postgresql/factories/process.py`:
- Around line 96-107: Update the pg_ctl path checks in the surrounding
executable-discovery function to use os.path.isfile() instead of
os.path.exists() for both the configured postgresql_ctl value and each
discovered candidate, ensuring directories are rejected and invalid paths reach
ExecutableMissingException.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b7b1fe1-d3a7-4899-9e2e-99622e9149e9

📥 Commits

Reviewing files that changed from the base of the PR and between b2b0ed9 and 472876d.

📒 Files selected for processing (1)
  • pytest_postgresql/factories/process.py

Comment thread pytest_postgresql/factories/process.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pytest_postgresql/factories/process.py`:
- Line 56: Update _pg_bindir to pass a finite timeout to subprocess.check_output
when invoking pg_config, preserving the existing SubprocessError handling so
TimeoutExpired is handled consistently.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7e239636-9fd3-475b-8c72-4b15a5367ad0

📥 Commits

Reviewing files that changed from the base of the PR and between 472876d and 98c9caf.

📒 Files selected for processing (1)
  • pytest_postgresql/factories/process.py

Comment thread pytest_postgresql/factories/process.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pytest_postgresql/factories/process.py`:
- Around line 108-119: Update _pg_exe to require execute permission when
accepting configured and _pg_bindir-discovered pg_ctl candidates, using an
appropriate executable-file check; leave explicit factory arguments unvalidated.
Preserve the existing candidate search and ExecutableMissingException behavior,
and add regression coverage for non-executable configured and discovered
candidates.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 76003069-c14a-47c6-adfd-302d4658d6cc

📥 Commits

Reviewing files that changed from the base of the PR and between 98c9caf and 98c314f.

📒 Files selected for processing (2)
  • pytest_postgresql/factories/process.py
  • tests/test_pg_exe.py

Comment thread pytest_postgresql/factories/process.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pytest_postgresql/factories/_pg.py`:
- Line 7: Update the import used by the annotations in the module to import
Iterable from collections.abc instead of typing, while preserving the existing
annotation contract and usage.

In `@tests/test_executor.py`:
- Line 520: Update all six patch decorators in the affected tests to target the
local binding used by postgresql_proc, replacing
pytest_postgresql.factories._pg._pg_exe with
pytest_postgresql.factories.process._pg_exe so raw_func invokes the mocked
executor.

In `@tests/test_pg_exe.py`:
- Around line 96-97: Combine the nested patch and pytest.raises context managers
in each affected test into a single with statement. Update the tests around the
visible subprocess.check_output patches and ExecutableMissingException
assertions, including all four reported locations, while preserving the existing
patch arguments, exception matching, and test behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8645f445-b50b-4ea6-8fee-14d3767f2b65

📥 Commits

Reviewing files that changed from the base of the PR and between 666388c and 0bc60c0.

📒 Files selected for processing (4)
  • pytest_postgresql/factories/_pg.py
  • pytest_postgresql/factories/process.py
  • tests/test_executor.py
  • tests/test_pg_exe.py

Comment thread pytest_postgresql/factories/_pg.py
Comment thread tests/test_executor.py Outdated

with (
patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),
patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Patch the binding used by postgresql_proc.

pytest_postgresql.factories.process imports _pg_exe into its own module namespace, and postgresql_proc calls that local binding. (raw.githubusercontent.com)

Patching pytest_postgresql.factories._pg._pg_exe at Line [520], Line [557], Line [607], Line [660], Line [698], and Line [744] does not replace the function that raw_func(...) invokes. These tests can run real discovery with config_mock and fail before the mocked executor is reached.

Change each patch target to pytest_postgresql.factories.process._pg_exe.

Proposed fix
-            patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),
+            patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),

Also applies to: 557-557, 607-607, 660-660, 698-698, 744-744

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_executor.py` at line 520, Update all six patch decorators in the
affected tests to target the local binding used by postgresql_proc, replacing
pytest_postgresql.factories._pg._pg_exe with
pytest_postgresql.factories.process._pg_exe so raw_func invokes the mocked
executor.

Comment thread tests/test_pg_exe.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_executor.py`:
- Line 557: Update the patch targets at the five executor test sites surrounding
the relevant mocked process cases to patch the binding used by postgresql_proc:
replace pytest_postgresql.factories._pg._pg_exe with
pytest_postgresql.factories.process._pg_exe, preserving the existing return
value and test behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fbb3ba2b-953b-42c3-8a4c-9c6f475ec8f3

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc60c0 and f40ab44.

📒 Files selected for processing (1)
  • tests/test_executor.py

Comment thread tests/test_executor.py Outdated

with (
patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),
patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical

Patch the binding used by postgresql_proc.

pytest_postgresql.factories.process calls its imported local _pg_exe binding. Patching pytest_postgresql.factories._pg._pg_exe does not replace that binding. These tests can execute real executable discovery before the mocked process behaviour is reached.

Change the patch target at Line 557, Line 607, Line 660, Line 698, and Line 744 to pytest_postgresql.factories.process._pg_exe.

Proposed fix
- patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),
+ patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),

Also applies to: 607-607, 660-660, 698-698, 744-744

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_executor.py` at line 557, Update the patch targets at the five
executor test sites surrounding the relevant mocked process cases to patch the
binding used by postgresql_proc: replace pytest_postgresql.factories._pg._pg_exe
with pytest_postgresql.factories.process._pg_exe, preserving the existing return
value and test behavior.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_executor.py`:
- Line 607: Update the patch target in the tests using postgresql_proc so they
patch the local binding consumed by pytest_postgresql.factories.process: change
each pytest_postgresql.factories._pg._pg_exe target to
pytest_postgresql.factories.process._pg_exe at all four occurrences. Preserve
the existing mocked return value and test behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ad4bac4d-f98d-47ca-a36c-462fef018953

📥 Commits

Reviewing files that changed from the base of the PR and between f40ab44 and c24c288.

📒 Files selected for processing (1)
  • tests/test_executor.py

Comment thread tests/test_executor.py

with (
patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),
patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Patch the binding used by postgresql_proc.

pytest_postgresql.factories.process imports _pg_exe into its own module namespace, and postgresql_proc calls that local binding. Patching pytest_postgresql.factories._pg._pg_exe at Lines [607], [660], [698], and [744] does not replace the function used by raw_func(...). These tests can perform real executable discovery with config_mock and fail before the mocked executor or port behaviour is reached. Change each target to pytest_postgresql.factories.process._pg_exe.

Proposed fix
-            patch("pytest_postgresql.factories._pg._pg_exe", return_value="/usr/bin/pg_ctl"),
+            patch("pytest_postgresql.factories.process._pg_exe", return_value="/usr/bin/pg_ctl"),

Also applies to: 660-660, 698-698, 744-744

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_executor.py` at line 607, Update the patch target in the tests
using postgresql_proc so they patch the local binding consumed by
pytest_postgresql.factories.process: change each
pytest_postgresql.factories._pg._pg_exe target to
pytest_postgresql.factories.process._pg_exe at all four occurrences. Preserve
the existing mocked return value and test behavior.

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.

1 participant