Skip to content

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

@panovitcin

Description

@panovitcin

Bug report

Bug description:

root issue is here ( discussed w\ @zzzeek ): sqlalchemy/sqlalchemy#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

Metadata

Metadata

Labels

docsDocumentation in the Doc dirstdlibPython modules in the Lib dirtopic-sqlite3type-bugAn unexpected behavior, bug, or error

Projects

Status

In Progress

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions