Skip to content

sqlite3 context manager does not close in-memory database #135333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pnsaevik opened this issue Jun 10, 2025 · 2 comments
Closed

sqlite3 context manager does not close in-memory database #135333

pnsaevik opened this issue Jun 10, 2025 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@pnsaevik
Copy link

pnsaevik commented Jun 10, 2025

Bug report

Bug description:

import sqlite3

with sqlite3.connect(':memory:') as conn:
    pass

Run code with "python -Werror myscript.py" to reproduce

The following does not raise a warning:

import sqlite3

conn = sqlite3.connect(':memory:')
conn.close()

The bug is not present in python 3.12 since no warnings are raised on unclosed sqlite databases before 3.13

CPython versions tested on:

3.13

Operating systems tested on:

Windows

@pnsaevik pnsaevik added the type-bug An unexpected behavior, bug, or error label Jun 10, 2025
@erlend-aasland
Copy link
Contributor

The sqlite3 context manager is not a closing context manager. See the docs for details:

@erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2025
@pnsaevik
Copy link
Author

I had no idea, thanks. I've gotten too used to closing context managers I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants