GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sqlite3: fix Connection.cursor() factory argument handling by ever0de · Pull Request #6783 · RustPython/RustPython

Conversation

@ever0de

@ever0de ever0de commented Jan 18, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

fixed #6782

CPython Reference

  • pysqlite_connection_cursor_impl
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.

All reactions
@ever0de
sqlite3: fix Connection.cursor() factory argument handling
bf872a9
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

coderabbitai Bot commented Jan 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 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

  • ShaharNaveh

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
  • 📝 Generate docstrings

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands and usage tips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

youknowone
youknowone approved these changes Jan 18, 2026
View reviewed changes

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

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.

All reactions
@ever0de

ever0de commented Jan 18, 2026

Copy link
Copy Markdown
Contributor Author

👍 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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone

youknowone commented Jan 18, 2026

Copy link
Copy Markdown
Member

Sure, that will take time. We have a lot of things to do to reach there

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone

youknowone commented Jan 18, 2026

Copy link
Copy Markdown
Member

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.

@ever0de

ever0de commented Jan 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone merged commit 050db47 into RustPython:main Jan 18, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai coderabbitai Bot mentioned this pull request Feb 28, 2026
sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() … #7278
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@youknowone youknowone youknowone approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

sqlite3: Fix failing test_is_instance in CursorFactoryTests

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ever0de @youknowone
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.