Skip to content

sqlite3: fix isolation_level TypeError message to match CPython - #8313

Merged
youknowone merged 1 commit into
RustPython:mainfrom
ever0de:fix/sqlite-isolation-level-type-error-message
Jul 19, 2026
Merged

sqlite3: fix isolation_level TypeError message to match CPython#8313
youknowone merged 1 commit into
RustPython:mainfrom
ever0de:fix/sqlite-isolation-level-type-error-message

Conversation

@ever0de

@ever0de ever0de commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the isolation_level argument type validation in sqlite3.connect() and Connection.__init__() to raise a proper TypeError with the message "isolation_level must be str or None" when a non-str, non-None value is supplied, matching CPython behavior.

CPython reference: https://github.com/python/cpython/blob/60fdb3192b897168ec0418fb0ea6c8d2d49ea513/Modules/_sqlite/connection.c#L72-L93

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved SQLite connection handling for the isolation_level setting.
    • The Connection.isolation_level property now reliably accepts either a string value or None.
    • Changes are consistently applied during connection initialization and when updating the isolation level later, while preserving existing None behavior and ensuring transactional behavior stays aligned.

@coderabbitai

coderabbitai Bot commented Jul 18, 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: e5029a3a-1f4c-4b2d-a787-4b1477e00741

📥 Commits

Reviewing files that changed from the base of the PR and between f383600 and a71a04b.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sqlite3/test_regression.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/_sqlite3.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/stdlib/src/_sqlite3.rs

📝 Walkthrough

Walkthrough

The SQLite module adds typed parsing for isolation_level, updates ConnectArgs and traversal, unwraps the value during connection and database initialization, and updates the setter to preserve transaction behavior.

Changes

SQLite isolation level handling

Layer / File(s) Summary
Isolation level argument conversion
crates/stdlib/src/_sqlite3.rs
Adds IsolationLevelArg, accepts None or strings through TryFromObject, updates the argument default, and traverses the wrapped value.
Connection isolation level propagation
crates/stdlib/src/_sqlite3.rs
Uses the wrapped isolation level during connection construction, reinitialization, and database initialization.
Isolation level setter behavior
crates/stdlib/src/_sqlite3.rs
Accepts the wrapped setter value, unwraps it, and preserves transaction begin and commit behavior for string and None assignments.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 accurately summarizes the main CPython-compatibility change around sqlite3 isolation_level TypeError handling.
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.
✨ 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.

@ever0de
ever0de marked this pull request as draft July 18, 2026 08:42

@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 `@crates/stdlib/src/_sqlite3.rs`:
- Around line 354-355: Update the set_isolation_level setter to accept
PySetterValue<IsolationLevelArg> instead of PySetterValue<Option<PyStrRef>>, and
unwrap the IsolationLevelArg in its assignment branch before applying the value.
Preserve the existing setter behavior while ensuring invalid assignments use the
same custom TypeError handling as ConnectArgs.
- Around line 333-345: Update IsolationLevelArg::try_from_object so the
TypeError produced when downcast::<PyStr>() fails includes the rejected object's
type name, matching CPython's “isolation_level must be str or None, not {type}”
format. Use the PyObjectRef returned by the downcast error to obtain its class
name while preserving the existing acceptance of str and None.
🪄 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.yml

Review profile: CHILL

Plan: Pro

Run ID: 3b1bca36-d053-4c9f-ae2e-ad68479cb7bf

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc109d and 7d8349f.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sqlite3/test_regression.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/_sqlite3.rs

Comment thread crates/stdlib/src/_sqlite3.rs
Comment thread crates/stdlib/src/_sqlite3.rs
@ever0de
ever0de force-pushed the fix/sqlite-isolation-level-type-error-message branch 2 times, most recently from 774972c to f383600 Compare July 18, 2026 08:49
@ever0de
ever0de marked this pull request as ready for review July 18, 2026 08:52
@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/sqlite3
[x] test: cpython/Lib/test/test_sqlite3 (TODO: 80)

dependencies:

  • sqlite3

dependent tests: (2 tests)

  • sqlite3: test_dbm_sqlite3 test_sqlite3

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Assisted-by: GitHub Copilot:claude-sonnet-4-6
@ever0de
ever0de force-pushed the fix/sqlite-isolation-level-type-error-message branch from f383600 to a71a04b Compare July 18, 2026 10:24

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@youknowone
youknowone merged commit 6f9e3a1 into RustPython:main Jul 19, 2026
27 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 27, 2026
2 tasks
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.

2 participants