Add proxy for autocommit property on Connection#312
Conversation
|
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 |
amyreese
left a comment
There was a problem hiding this comment.
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)
|
It turns out this property is actually a bit difficult to support. With the test, @skipIf(sys.version_info < (3, 12), "3.12 sqlite3 library feature")
async def test_autocommit_property(self):
async with aiosqlite.connect(TEST_DB) as db:
self.assertEqual(db.autocommit, db._conn.autocommit)I get |
Description
Add a proxy property for the
autocommitproperty onsqlite3.Connectionobjects.Use Case
I want
autocommit=Falseas suggested by thesqlite3docs (see docs). I also want to setPRAGMA journal_mode = WAL. The issue is that I can't change thejournal_modewhen in a transaction, which is always the case whenautocommit=False. So the solution is to set theautocommitproperty after setting thejournal_mode. This works fine insqlite3, butaiosqlitedoesn't have the property.I can work around this by simply reaching into the
aiosqlite.Connectionobject and accessing the_connattribute, but this is clearly not ideal.