Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SQLite connections are not closed when calling .close() in 3.11 #103837

Copy link
Copy link

Description

@jhoekx
Issue body actions

Bug report

In our tests we are using in-memory SQLite databases with a shared cache. This makes it possible to create multiple connections with the same connection string and see the same data, as recommended in In-Memory Databases. After updating from Python 3.10 to 3.11 our tests started failing.

The minimal reproduction case:

import sqlite3
import pytest

def write_value():
    with sqlite3.connect("file:test?mode=memory&cache=shared", uri=True) as db:
        db.execute("insert into Test (value) values ('hello')")


@pytest.fixture
def db():
    conn_1 = sqlite3.connect("file:test?mode=memory&cache=shared", uri=True)
    conn_1.execute("create table Test (value text, unique(value))")
    yield write_value
    conn_1.close()


def test_hello_1(db):
    db()


def test_hello_2(db):
    db()

This works in 3.10 (and worked in 3.8 and 3.9), but fails in 3.11:

ERROR sqlite-connection-close.py::test_hello_2 - sqlite3.OperationalError: table Test already exists

The SQLite documentations includes:

The database is automatically deleted and memory is reclaimed when the last connection to the database closes.

We used a workaround mentioned in #97641 for now (calling gc.collect()).
I opened a new issue, since that one looks similar, but is Windows specific, while this one happens on Linux as well.

Your environment

  • CPython versions tested on: 3.10.10, 3.11.3
  • Operating system and architecture: both on Ubuntu 22.04 (from deadsnakes PPA) and Arch (AUR)
  • SQLite versions: 3.37.2 and 3.41.2
Reactions are currently unavailable

Metadata

Metadata

Labels

No fields configured for issues without a type.

Projects

Status
Discarded
Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.