python / python/cpython

Sending the sqlite3 autocommit parameter renders this PRAGMA command a no-op

Open
#137,205 13 comments 0 reactions 1 assignee View on GitHub

@erlend-aasland is already working on this.

Since Aug 6, 2025.

docs stdlib topic-sqlite3 type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

root issue is here ( discussed w\ @zzzeek ): https://github.com/sqlalchemy/sqlalchemy/discussions/12767

An explicit emit of the autocommit attribute (=False) makes PRAGMA command not work. Example of the code:

engine = create_async_engine(
    config.SQLITE_URL,
    echo=True,
    connect_args={"autocommit": False},
    poolclass=NullPool
)

@event.listens_for(engine.sync_engine, "connect", named=True)
def enable_foreign_keys(dbapi_connection: AsyncAdapt_aiosqlite_connection, connection_record):
    cursor = dbapi_connection.cursor()
    cursor.execute("PRAGMA foreign_keys=ON")
    cursor.execute("PRAGMA foreign_keys")
    result = cursor.fetchone() 
    print(f"Foreign keys pragma value: {result}")
    cursor.close()
CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs
  • gh-137505

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.