Skip to content

fix(wren): connect MSSqlConnector with autocommit so statements are not left in an open transaction - #2705

Open
AmirF194 wants to merge 1 commit into
Canner:mainfrom
AmirF194:fix/mssql-connector-autocommit
Open

fix(wren): connect MSSqlConnector with autocommit so statements are not left in an open transaction#2705
AmirF194 wants to merge 1 commit into
Canner:mainfrom
AmirF194:fix/mssql-connector-autocommit

Conversation

@AmirF194

@AmirF194 AmirF194 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

MSSqlConnector opens its pyodbc connection without autocommit=True, so every statement runs inside one implicit transaction that is never committed for the connection's whole process life. This connects autocommit=True in _connect_mssql_pyodbc, matching the shape already used by canner.py, mysql.py, and redshift.py.

What failure does this repair?

pyodbc defaults to autocommit=False. _connect_mssql_pyodbc calls pyodbc.connect(";".join(connection_parts)) with no autocommit argument, and nothing in mssql.py calls .commit(), .rollback(), or sets .autocommit afterward. Since WrenEngine._get_connector() caches this connector for the engine's lifetime, the connection stays in one open transaction for as long as the process runs, which blocks SQL Server's transaction log truncation for the whole time (log_reuse_wait_desc = 'ACTIVE_TRANSACTION') and leaves any write statement issued through the connector uncommitted.

Fixes #2704.

How is it tested?

  • New unit test test_mssql_connects_with_autocommit in tests/unit/test_mssql_connection.py, which patches wren.connector.mssql.pyodbc (same fixture the file's other tests already use) and asserts pyodbc.connect is called with autocommit=True. Runs in CI's test-unit job (pytest tests/unit/).
  • Docker differential against the same test file, both directions, python:3.11-slim, dependencies from uv sync --locked (which resolves the published wren-core-py==0.7.5 wheel, no local Rust build needed since this change does not touch wren-core-py): 1 failed / 18 passed on unmodified main (56e007d), 19 passed on this branch.
  • Full tests/unit/ (excluding test_memory.py / test_mcp_server.py, matching wren-ci.yml's test-unit job exactly): 1240 passed, 2 skipped, on the branch.
  • ruff format --check src/ and ruff check src/ (the lint job's exact commands): clean.
  • Not run: tests/connectors/test_mssql.py, the live-SQL-Server integration suite. It needs testcontainers[mssql] and a real SQL Server container, and wren-ci.yml's test-connector matrix only covers postgres/mysql, so this file does not execute in CI either. I read it to confirm the fault (its own setup connections already do conn.autocommit = True, working around the exact gap this PR closes) but did not attempt to stand up a container for it.

Duplicate check

competing-prs.sh against core/wren/src/wren/connector/mssql.py, run at scout time and again immediately before this push (70/70 open PRs swept both times): 2 candidates, #2551 and #2552, both drafts from the same author reworking row-limit handling in MSSqlConnector.query. Neither touches connection setup, autocommit, or transactions.

Summary by CodeRabbit

  • Bug Fixes
    • MSSQL connections now automatically commit statements, helping prevent changes from remaining in uncommitted transactions.
  • Tests
    • Added coverage to verify that MSSQL connections use automatic commit behavior.

…ot left in an open transaction

pyodbc defaults to autocommit=False, and mssql.py never called .commit() or
set .autocommit, so every statement on the process-cached connection ran
inside one transaction that was never closed. Mirrors canner.py, mysql.py,
and redshift.py, which already turn autocommit on.

Fixes Canner#2704.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d598feb4-40be-46d5-a251-1315cd52e337

📥 Commits

Reviewing files that changed from the base of the PR and between 56e007d and 27760e5.

📒 Files selected for processing (2)
  • core/wren/src/wren/connector/mssql.py
  • core/wren/tests/unit/test_mssql_connection.py

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


Walkthrough

The MSSQL connector now enables autocommit when it creates its cached pyodbc connection. A unit test verifies that pyodbc.connect receives autocommit=True.

Changes

MSSQL autocommit

Layer / File(s) Summary
Enable and verify connection autocommit
core/wren/src/wren/connector/mssql.py, core/wren/tests/unit/test_mssql_connection.py
_connect_mssql_pyodbc passes autocommit=True to pyodbc.connect. The unit test verifies the connection call and keyword argument.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: 🔵 Low · up to 27760

This change prevents long-lived uncommitted MSSQL transactions and makes successful statements durable immediately. It is mergeable with owner awareness that multi-statement write workflows may no longer be atomic if a later statement fails.

Suggested reviewers: bartok9

Poem

A rabbit checks the connection bright

Autocommit hops into sight
The test guards the setting true
Transactions finish as they should do
Ears up, the MSSQL path is right

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: enabling autocommit for MSSqlConnector to prevent open transactions.
Description check ✅ Passed The description includes the required Summary, failure analysis, testing details, and duplicate check. It explains the observed transaction issue and reports relevant validation results.
Linked Issues check ✅ Passed The PR satisfies issue #2704 by passing autocommit=True to pyodbc.connect and adding a regression test that verifies the argument.
Out of Scope Changes check ✅ Passed The changes are limited to MSSQL connection behavior and its unit test. No unrelated code changes are present.
  • Fix all pre-merge checks with AI
✨ 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

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSSqlConnector never enables autocommit, so every SQL Server session runs inside one never-committed transaction for the connector's process life

1 participant