Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy for autocommit property on Connection #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathan-d-zhang
Copy link

Description

Add a proxy property for the autocommit property on sqlite3.Connection objects.

Use Case

I want autocommit=False as suggested by the sqlite3 docs (see docs). I also want to set PRAGMA journal_mode = WAL. The issue is that I can't change the journal_mode when in a transaction, which is always the case when autocommit=False. So the solution is to set the autocommit property after setting the journal_mode. This works fine in sqlite3, but aiosqlite doesn't have the property.

I can work around this by simply reaching into the aiosqlite.Connection object and accessing the _conn attribute, but this is clearly not ideal.

@amyreese
Copy link
Member

amyreese commented Feb 3, 2025

Looks like this is a new feature in sqlite for Python 3.12. Can you update this to raise an exception accordingly so that mypy passes cleanly? Also, a simple test case would be appreciated (and I'd be ok with something like @skipIf(sys.version_info < (3,12))).

Copy link
Member

@amyreese amyreese left a comment

Choose a reason for hiding this comment

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

Mypy fails because this is a 3.12 feature:

python -m mypy -p aiosqlite
aiosqlite/core.py:246: error: "Connection" has no attribute "autocommit"  [attr-defined]
Found 1 error in 1 file (checked 10 source files)

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