Fix for test failure against sqlean

This commit is contained in:
Simon Willison 2026-07-05 12:16:11 -07:00
commit 623331b3f4
2 changed files with 17 additions and 4 deletions

View file

@ -713,10 +713,14 @@ class Database:
args: tuple = (params,) if params is not None else () args: tuple = (params,) if params is not None else ()
if keyword == "PRAGMA": if keyword == "PRAGMA":
# Some PRAGMA statements refuse to run inside a transaction, so # Some PRAGMA statements refuse to run inside a transaction, so
# execute these without the savepoint guard used below. PRAGMAs # execute these without the savepoint guard used below. Some
# never open an implicit transaction, so there is nothing to # adapters open an implicit transaction before comment-prefixed
# undo if this one turns out not to return rows # PRAGMAs, so temporarily use driver autocommit when it is safe.
cursor = self.conn.execute(sql, *args) if self.conn.in_transaction:
cursor = self.conn.execute(sql, *args)
else:
with self.ensure_autocommit_off():
cursor = self.conn.execute(sql, *args)
if cursor.description is None: if cursor.description is None:
raise ValueError(message) raise ValueError(message)
keys = [d[0] for d in cursor.description] keys = [d[0] for d in cursor.description]

View file

@ -114,6 +114,15 @@ def test_query_comment_prefixed_pragma(tmpdir):
db.close() db.close()
def test_query_comment_prefixed_pragma_inside_transaction(fresh_db):
fresh_db.begin()
assert list(fresh_db.query("-- check version\npragma user_version")) == [
{"user_version": 0}
]
assert fresh_db.conn.in_transaction
fresh_db.rollback()
@pytest.mark.parametrize( @pytest.mark.parametrize(
"sql,expected", "sql,expected",
[ [