Skip to content

sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() …#7278

Merged
youknowone merged 1 commit intoRustPython:mainfrom
ever0de:fix/cursor-row-factory-pygetset
Mar 1, 2026
Merged

sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() …#7278
youknowone merged 1 commit intoRustPython:mainfrom
ever0de:fix/cursor-row-factory-pygetset

Conversation

@ever0de
Copy link
Contributor

@ever0de ever0de commented Feb 28, 2026

…propagation

Add #[pygetset] getter/setter for Cursor.row_factory so that Python-level attribute access reads/writes the Rust struct field instead of the instance dict.

Fix Connection.cursor() to only propagate the connection's row_factory to the cursor when the connection's row_factory is not None, matching CPython behavior. Previously it unconditionally overwrote the cursor's row_factory, discarding any factory set by a cursor subclass init.

Summary by CodeRabbit

Release Notes

  • New Features

    • Cursor objects now provide public methods to get and set row factory configurations.
  • Bug Fixes

    • Improved row factory handling during cursor initialization for increased reliability.

…propagation

Add #[pygetset] getter/setter for Cursor.row_factory so that Python-level
attribute access reads/writes the Rust struct field instead of the
instance dict.

Fix Connection.cursor() to only propagate the connection's row_factory
to the cursor when the connection's row_factory is not None, matching
CPython behavior. Previously it unconditionally overwrote the cursor's
row_factory, discarding any factory set by a cursor subclass __init__.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2833cd8 and ab4e638.

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

📝 Walkthrough

Walkthrough

Modified row_factory transfer logic in Cursor wrapping to add conditions for downcast capability and factory presence. Added two public accessor methods to the Cursor class: row_factory() for retrieving the current row_factory and set_row_factory() for updating it.

Changes

Cohort / File(s) Summary
Cursor row_factory Management
crates/stdlib/src/_sqlite3.rs
Tightened guard condition for row_factory transfer during Cursor wrapping to check downcast capability and factory presence; added public accessor methods row_factory() and set_row_factory() to the Cursor class.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 Guarded row_factories now take flight,
Cursor accessors shining bright,
Logic tightened, conditions just right,
SQLite hops with pure delight! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: adding Cursor.row_factory pygetset accessors and fixing Connection.cursor() propagation behavior.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions
Copy link
Contributor

📦 Library Dependencies

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

Error: 'frozenset' object has no attribute 'discard'

Legend:

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

@fanninpm
Copy link
Contributor

Error: 'frozenset' object has no attribute 'discard'

@ShaharNaveh you may want to take a look into this

@ShaharNaveh
Copy link
Contributor

Error: 'frozenset' object has no attribute 'discard'

@ShaharNaveh you may want to take a look into this

#7276 :)

@youknowone youknowone merged commit 7b7c7a1 into RustPython:main Mar 1, 2026
14 checks passed
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.

4 participants