Skip to content

gh-149738: Fix segmentation fault bug in sqllite3#149754

Open
sepehr-rs wants to merge 11 commits into
python:mainfrom
sepehr-rs:fix-149738
Open

gh-149738: Fix segmentation fault bug in sqllite3#149754
sepehr-rs wants to merge 11 commits into
python:mainfrom
sepehr-rs:fix-149738

Conversation

@sepehr-rs
Copy link
Copy Markdown

@sepehr-rs sepehr-rs commented May 13, 2026

Fixes #149738.

>>> import sqlite3
>>> db = sqlite3.connect(":memory:")
>>> del db.row_factory
>>> db.execute("test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    db.execute("test")
    ~~~~~~~~~~^^^^^^^^
sqlite3.OperationalError: near "test": syntax error
>>> 

Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

We need tests and check what happens on the created connection after deletion (check that there is still a row factory on the newly created cursor)

@sepehr-rs
Copy link
Copy Markdown
Author

sepehr-rs commented May 13, 2026

Thanks for your comment and review, @picnixz!
I’ve added the tests as requested and would appreciate any feedback.

P.S. The Read the Docs build is failing, but the logs indicate it’s due to an external issue unrelated to my changes.

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I would prefer using connection_getset instead of connection_members for row_factory and text_factory to raise an exception if the developer tries to delete the attribute (set it to NULL). Add get/set on these attributes.

@sepehr-rs
Copy link
Copy Markdown
Author

Hi @vstinner! Thank you for your kind review. Sorry for the delay, GitHub access has been unreliable here recently.
I’ve made the requested changes and would appreciate your feedback when you have a chance.

Comment thread Modules/_sqlite/connection.c
Comment thread Modules/_sqlite/connection.c Outdated
Comment thread Lib/test/test_sqlite3/test_factory.py
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-05-13-06-54-41.gh-issue-149738.4BLFoH.rst Outdated
@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deleting sqlite3 row_factory causes segfault

3 participants