GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Emit resource warning if sqlite3 fails to close the database · Issue #105539 · python/cpython

Emit resource warning if sqlite3 fails to close the database #105539

New issue
Copy link
New issue
Copy link
Closed
Closed
Emit resource warning if sqlite3 fails to close the database#105539
#108017 (+2)
Copy link
Assignees
erlend-aasland
Labels
3.13only security fixesonly security fixestopic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

Description

@erlend-aasland
erlend-aasland
opened on Jun 8, 2023
Issue body actions

See #103837 (comment) and #103837 (comment):

EAA:

I still think we should consider changing the underlying API so we can emit a resource warning if close failed.

VS:

IMO sqlite3 should be modified to emit a ResourceWarning.

Currently, no ResourceWarning is emitted when a connection is not closed explicitly:

Linked PRs

  • gh-105539: Emit ResourceWarning if sqlite3 database is not closed explicitly #108015
  • gh-105539: Explict resource management for connection objects in sqlite3 tests #108017
  • gh-105539: Fix ResourceWarning from unclosed SQLite connection in ClosedCurTests. #108360
  • gh-64662: Fix NEWS entry and remove What's New entry #108565

Activity

  1. erlend-aasland
    self-assigned this
    on Jun 8, 2023
  2. erlend-aasland
    added
    topic-sqlite3
    3.13only security fixesonly security fixes
    type-featureA feature request or enhancementA feature request or enhancement
    on Jun 8, 2023
  3. erlend-aasland
    added this to sqlite3 issueson Jun 8, 2023
  4. erlend-aasland
    moved this to TODO: Feature in sqlite3 issueson Jun 8, 2023
  5. erlend-aasland
    added a commit that references this issue on Aug 16, 2023

    pythongh-105539: Emit ResourceWarning if sqlite3 database is not clos…

    4a8d209
  6. erlend-aasland
    moved this from TODO: Feature to In Progress in sqlite3 issueson Aug 16, 2023
  7. vstinner commented on Aug 16, 2023

    @vstinner
    vstinner
    on Aug 16, 2023
    Member
    More actions

    What is the consequences if a database is not closed explicitly and fails to be closed at Python exit? Is there a risk of losing data?

  8. erlend-aasland commented on Aug 16, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 16, 2023
    ContributorAuthor
    More actions

    What is the consequences if a database is not closed explicitly and fails to be closed at Python exit? Is there a risk of losing data?

    If sqlite3_close() or sqlite3_close_v2() fails, there is of course a risk of losing data. However, we do a pretty good job at cleaning up the connection and its debris (cursors, statements, registered callbacks, etc.), so that risk is almost non-existent :)

  9. erlend-aasland
    added a commit that references this issue on Aug 16, 2023

    pythongh-105539: Explict resource management for connection objects i…

    6af3de4
  10. vstinner commented on Aug 16, 2023

    @vstinner
    vstinner
    on Aug 16, 2023
    Member
    More actions

    By "fail to be closed", I was thinking about a database connection involved in a reference cycle which is impossible to break, and so close() is never called and the object is never destroyed.

  11. erlend-aasland commented on Aug 17, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 17, 2023
    ContributorAuthor
    More actions

    By "fail to be closed", I was thinking about a database connection involved in a reference cycle which is impossible to break, and so close() is never called and the object is never destroyed.

    If the connection object is never destroyed (dealloc or finalize are never called), there is no way to detect that in the extension module that I know about. The proposed change involves both the finalizer and the dealloc callbacks, so I'm relying on them actually being called at some point.

  12. erlend-aasland
    added 2 commits that reference this issue on Aug 17, 2023

    gh-105539: Explict resource management for connection objects in sqli…

    1344cfa

    gh-105539: Emit ResourceWarning if sqlite3 database is not closed exp…

    1a1bfc2
  13. erlend-aasland
    closed this as completedon Aug 22, 2023
  14. github-project-automation
    moved this from In Progress to Done in sqlite3 issueson Aug 22, 2023
  15. vstinner commented on Aug 22, 2023

    @vstinner
    vstinner
    on Aug 22, 2023
    Member
    More actions

    Congrats :-) IMO it's a nice enhancement.

    Reacted by Erlend E. Aasland
  16. erlend-aasland commented on Aug 22, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 22, 2023
    ContributorAuthor
    More actions

    Thanks for bringing the idea up in the first place, Victor! :)

  17. erlend-aasland
    reopened this on Aug 23, 2023
  18. erlend-aasland commented on Aug 23, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 23, 2023
    ContributorAuthor
    More actions

    Apparently, I did not cover all cases in #108017; the following now emit resource warnings:

     ./python.exe -m test -R : test_sqlite3 -m ClosedCurTests 
    
  19. felixxm
    added a commit that references this issue on Aug 23, 2023

    pythongh-105539: Fix ResourceWarning from unclosed SQLite connection …

    02851c2
  20. erlend-aasland
    linked a pull request that will close this issuegh-105539: Fix ResourceWarning from unclosed SQLite connection in ClosedCurTests. #108360on Aug 23, 2023
  21. erlend-aasland
    linked a pull request that will close this issuegh-105539: Emit ResourceWarning if sqlite3 database is not closed explicitly #108015on Aug 23, 2023
  22. erlend-aasland
    linked a pull request that will close this issuegh-105539: Explict resource management for connection objects in sqlite3 tests #108017on Aug 23, 2023
  23. felixxm
    added a commit that references this issue on Aug 23, 2023

    pythongh-105539: Fix ResourceWarning from unclosed SQLite connection …

    5c30ad3
  24. erlend-aasland
    closed this as completedin #108360on Aug 23, 2023
  25. erlend-aasland
    added 2 commits that reference this issue on Aug 23, 2023

    gh-105539: Fix ResourceWarning from unclosed SQLite connections in te…

    29bc616

    pythongh-105539: Fix NEWS entry and remove What's New entry

    9a5bfa7
  26. reece
    added a commit that references this issue on Nov 10, 2025

    Suppress Python 3.13+ sqlite3 ResourceWarnings from third-party libra…

    3b2731d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @erlend-aasland
    erlend-aasland

Labels

3.13only security fixesonly security fixestopic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

Projects

  • sqlite3 issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.