Skip to content

Pass autocomit to the janitor's load methods - closes #902 - #1383

Open
fizyk wants to merge 5 commits into
mainfrom
issue-902
Open

Pass autocomit to the janitor's load methods - closes #902#1383
fizyk wants to merge 5 commits into
mainfrom
issue-902

Conversation

@fizyk

@fizyk fizyk commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added load_autocommit to control autocommit for the PostgreSQL SQL loader connection.
    • Allows loading .sql files with statements that must not run inside a transaction (e.g. CREATE DATABASE).
    • Configure via a pytest setting, a command-line flag, or proc/noproc fixture/factory arguments.
  • Documentation

    • Documented the new option, CLI flag, and updated examples.
  • Breaking Changes

    • Loaded SQL loader callables now need to accept an additional autocommit argument; positional argument compatibility was affected.
  • Tests

    • Added and updated tests to verify parsing and correct autocommit forwarding to the loader connection.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds load_autocommit configuration, fixture factory parameters, pytest options, and janitor forwarding so SQL loader connections can run with autocommit enabled. Documentation and synchronous/asynchronous tests cover the configuration paths.

Changes

SQL loader autocommit

Layer / File(s) Summary
Configuration and factory wiring
pytest_postgresql/config.py, pytest_postgresql/plugin.py, pytest_postgresql/factories/*
Adds the load_autocommit configuration field, CLI and ini options, and factory parameters that pass the setting to DatabaseJanitor.
Janitor loader forwarding
pytest_postgresql/janitor.py
Stores the autocommit setting and forwards it to synchronous and asynchronous SQL loader connections.
Validation and documentation
README.rst, newsfragments/*, tests/*
Documents the supported configuration methods and tests default, enabled, and chained loader autocommit propagation.

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

Sequence Diagram(s)

sequenceDiagram
  participant PytestOptions
  participant get_config
  participant postgresql_proc
  participant DatabaseJanitor
  participant SQLLoader
  PytestOptions->>get_config: Read postgresql_load_autocommit
  get_config->>postgresql_proc: Provide load_autocommit
  postgresql_proc->>DatabaseJanitor: Construct with autocommit
  DatabaseJanitor->>SQLLoader: Load SQL with autocommit
Loading

Suggested labels: Feature

🚥 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 matches the main change: forwarding autocommit to the janitor load methods.
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 Newsfragments were added under newsfragments/ and match valid Towncrier types from pyproject.toml (feature, break).
✨ 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-902

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 Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
pytest_postgresql/factories/noprocess.py 66.66% 1 Missing ⚠️
pytest_postgresql/factories/process.py 66.66% 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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pytest_postgresql/janitor.py (1)

158-165: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Avoid breaking existing custom loaders.

Both janitor implementations unconditionally add autocommit to loader callables, breaking existing loaders that implement the documented five-argument contract.

  • pytest_postgresql/janitor.py#L158-L165: preserve compatibility for synchronous custom loaders.
  • pytest_postgresql/janitor.py#L263-L271: preserve compatibility for asynchronous and threaded custom loaders.
🤖 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 `@pytest_postgresql/janitor.py` around lines 158 - 165, Update the synchronous
loader invocation in pytest_postgresql/janitor.py:158-165 and the
asynchronous/threaded loader invocation in pytest_postgresql/janitor.py:263-271
so custom loaders using the documented five-argument contract are not passed
autocommit; preserve autocommit handling for loaders that support it while
maintaining compatibility at both call sites.
🤖 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/noprocess.py`:
- Line 120: Update load_autocommit resolution in
pytest_postgresql/factories/noprocess.py lines 120-120 and
pytest_postgresql/factories/process.py lines 227-227 to distinguish an
explicitly provided factory value, including False, from an omitted value; use
the factory setting when explicit and fall back to config.load_autocommit only
when omitted, preserving identical tri-state precedence in both sites.
- Around line 48-49: Update the factory signature containing load_autocommit and
depends_on to preserve existing positional binding: place load_autocommit after
depends_on, or make the trailing parameters keyword-only. Keep depends_on bound
to its original positional position.

In `@README.rst`:
- Around line 386-391: Update the “Noop process fixture” value for the
load_autocommit/--postgresql-load-autocommit configuration entry in the README
table from “-” to “yes”.

---

Outside diff comments:
In `@pytest_postgresql/janitor.py`:
- Around line 158-165: Update the synchronous loader invocation in
pytest_postgresql/janitor.py:158-165 and the asynchronous/threaded loader
invocation in pytest_postgresql/janitor.py:263-271 so custom loaders using the
documented five-argument contract are not passed autocommit; preserve autocommit
handling for loaders that support it while maintaining compatibility at both
call sites.
🪄 Autofix (Beta)

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: CHILL

Plan: Pro Plus

Run ID: 1ecf93ba-0f92-4334-b44e-1eef6ad20d97

📥 Commits

Reviewing files that changed from the base of the PR and between 06c3716 and 04c1be5.

📒 Files selected for processing (10)
  • README.rst
  • newsfragments/902.feature.rst
  • pytest_postgresql/config.py
  • pytest_postgresql/factories/noprocess.py
  • pytest_postgresql/factories/process.py
  • pytest_postgresql/janitor.py
  • pytest_postgresql/plugin.py
  • tests/examples/test_assert_load_autocommit_is_true.py
  • tests/test_janitor.py
  • tests/test_postgres_options_plugin.py

Comment thread pytest_postgresql/factories/noprocess.py Outdated
Comment thread pytest_postgresql/factories/noprocess.py Outdated
Comment thread README.rst

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.rst (1)

386-391: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix the no-process fixture’s configuration precedence.

postgresql_noproc defaults load_autocommit to False and then treats any non-None value as an explicit factory override. Consequently, --postgresql-load-autocommit and pytest.ini are ignored unless callers also pass the factory argument, despite this table documenting support.

Use a None default in pytest_postgresql/factories/noprocess.py, or document the limitation.

Proposed fix
-    load_autocommit: bool = False,
+    load_autocommit: bool | None = None,
🤖 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 `@README.rst` around lines 386 - 391, Update the postgresql_noproc factory’s
load_autocommit default to None so CLI and pytest.ini configuration can take
precedence unless callers explicitly provide a factory override; keep the
documented configuration keys and behavior unchanged.
🤖 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-97: Update the postgresql_proc factory signature so
load_autocommit is keyword-only by placing * before it, while preserving the
existing positional bindings for all preceding parameters and keeping
load_autocommit’s behavior unchanged.

---

Outside diff comments:
In `@README.rst`:
- Around line 386-391: Update the postgresql_noproc factory’s load_autocommit
default to None so CLI and pytest.ini configuration can take precedence unless
callers explicitly provide a factory override; keep the documented configuration
keys and behavior unchanged.
🪄 Autofix (Beta)

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: af9ffd88-e5a3-411f-adca-e46228bb9e46

📥 Commits

Reviewing files that changed from the base of the PR and between 04c1be5 and e9bd138.

📒 Files selected for processing (4)
  • README.rst
  • newsfragments/902.break.rst
  • pytest_postgresql/factories/noprocess.py
  • pytest_postgresql/factories/process.py

Comment thread pytest_postgresql/factories/process.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_chaining.py`:
- Line 10: Update the signatures of load_schema, load_data, and load_more_data
so autocommit is keyword-only by placing it after the keyword-only separator;
preserve existing parameter types and behavior, since callers already pass this
argument by keyword.
🪄 Autofix (Beta)

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: 7f898ab1-4977-4aea-bad0-2eae1b7c6fa7

📥 Commits

Reviewing files that changed from the base of the PR and between e9bd138 and 3c475da.

📒 Files selected for processing (3)
  • newsfragments/902.break.1.rst
  • pytest_postgresql/factories/noprocess.py
  • tests/test_chaining.py

Comment thread tests/test_chaining.py


def load_schema(host: str, port: int, user: str, dbname: str, password: str | None) -> None:
def load_schema(host: str, port: int, user: str, dbname: str, password: str | None, autocommit: bool) -> None:

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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make autocommit keyword-only.

Ruff flags each new boolean positional parameter (FBT001). The janitor already passes loader arguments by keyword, so this is a safe API clarification:

-def load_schema(host: str, port: int, user: str, dbname: str, password: str | None, autocommit: bool) -> None:
+def load_schema(host: str, port: int, user: str, dbname: str, password: str | None, *, autocommit: bool) -> None:

Apply the same change to load_data and load_more_data.

Also applies to: 19-19, 29-29

🧰 Tools
🪛 Ruff (0.15.21)

[warning] 10-10: Boolean-typed positional argument in function definition

(FBT001)

🤖 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_chaining.py` at line 10, Update the signatures of load_schema,
load_data, and load_more_data so autocommit is keyword-only by placing it after
the keyword-only separator; preserve existing parameter types and behavior,
since callers already pass this argument by keyword.

Source: Linters/SAST tools

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