GeezerVison is showing github.com — sqlite3: fix Connection.cursor() factory argument handling by ever0de · Pull Request #6783 · RustPython/RustPython
Conversation
ever0de
commented
Jan 18, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
fixed #6782
CPython Reference
static PyObject *
pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
{
if (factory == NULL) {
factory = (PyObject *)self->state->CursorType;
}
cursor = PyObject_CallOneArg(factory, (PyObject *)self);
if (!PyObject_TypeCheck(cursor, self->state->CursorType)) {
PyErr_Format(PyExc_TypeError,
"factory must return a cursor, not %.100s",
Py_TYPE(cursor)->tp_name);
...
}
...
}
Summary by CodeRabbit
- Refactor
- Improved SQLite cursor creation method to use a more structured argument approach
- Enhanced validation to ensure custom factory functions return proper Cursor objects
- Better alignment of row factory settings during cursor instantiation
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Fix test_is_instance in CursorFactoryTests by properly handling the
factory argument in Connection.cursor() method. Now the factory can
be passed as both positional and keyword argument, and returns the
correct subclass type instead of always returning PyRef<Cursor>.
- Use FromArgs derive macro with CursorArgs struct for argument parsing
- Return PyObjectRef instead of PyRef<Cursor> to allow subclasses
- Use fast_issubclass to validate returned cursor is a Cursor subclass
- Properly differentiate between 'no argument' and 'None passed'
coderabbitai
Bot
commented
Jan 18, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
This PR refactors the cursor() method in the SQLite Connection binding to properly handle custom factory arguments. The method signature changes to accept a CursorArgs struct and return a generic PyObjectRef instead of a concrete Cursor reference, enabling correct type validation and row_factory inheritance for custom cursor factories.
Changes
| Cohort / File(s) |
Summary |
SQLite Cursor Factory Handling crates/stdlib/src/sqlite.rs |
Updated cursor() method signature to use CursorArgs struct instead of OptionalArg<ArgCallable>. Refactored control flow to derive factory from args, invoke it with validation, and properly swap row_factory attributes. Added CursorArgs struct for optional factory parameter. Return type changed to PyObjectRef for generic cursor subclass support. (+25/-12 lines) |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- RustPython#6398 — Modifies Cursor and Connection type signatures in sqlite.rs, aligning with API changes for factory argument handling.
Suggested reviewers
Poem
🐰 A cursor seeks its factory gate,
With args in hand, it validates fate,
The row_factory's magic gleam,
Now flows through every custom scheme—
Fixed at last, the test's reprieve! ✨
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 change: fixing Connection.cursor() factory argument handling, which is the core objective of the PR. |
| Linked Issues check |
✅ Passed |
The changes directly address issue #6782 by implementing proper factory argument parsing, validating returned objects as Cursor subclasses, and distinguishing between missing and None arguments. |
| Out of Scope Changes check |
✅ Passed |
All changes are focused on fixing the Connection.cursor() factory argument handling; no unrelated modifications detected. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.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
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 are you also interested in upgrading sqlite python library to 3.14?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
👍 are you also interested in upgrading sqlite python library to 3.14?
Sure! I noticed the discussion in issue #5974 regarding automated updates is still ongoing. Should I proceed with porting it directly from CPython for now?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sure, that will take time. We have a lot of things to do to reach there
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Oh! don't forget to use scripts/lib_updater.py. That will be quite automatic
|
ever0de reacted with thumbs up emoji
ever0de reacted with eyes emoji
All reactions
-
👍
1 reaction
-
👀
1 reaction
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|