Skip to content
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

SELECT-initiated transactions can cause "database is locked" in sqlite #70812

Closed
rhunter mannequin opened this issue Mar 23, 2016 · 2 comments
Closed

SELECT-initiated transactions can cause "database is locked" in sqlite #70812

rhunter mannequin opened this issue Mar 23, 2016 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhunter
Copy link
Mannequin

rhunter mannequin commented Mar 23, 2016

BPO 26625
Superseder
  • bpo-9924: sqlite3 SELECT does not BEGIN a transaction, but should according to spec
  • Files
  • unintuitive_sqlite_behavior.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-03-23.16:31:37.202>
    created_at = <Date 2016-03-23.16:28:34.008>
    labels = ['type-bug', 'library']
    title = 'SELECT-initiated transactions can cause "database is locked" in sqlite'
    updated_at = <Date 2016-03-23.17:29:08.114>
    user = 'https://bugs.python.org/rhunter'

    bugs.python.org fields:

    activity = <Date 2016-03-23.17:29:08.114>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-03-23.16:31:37.202>
    closer = 'rhunter'
    components = ['Library (Lib)']
    creation = <Date 2016-03-23.16:28:34.008>
    creator = 'rhunter'
    dependencies = []
    files = ['42259']
    hgrepos = []
    issue_num = 26625
    keywords = []
    message_count = 2.0
    messages = ['262282', '262283']
    nosy_count = 1.0
    nosy_names = ['rhunter']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '9924'
    type = 'behavior'
    url = 'https://bugs.python.org/issue26625'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @rhunter
    Copy link
    Mannequin Author

    rhunter mannequin commented Mar 23, 2016

    When a transaction starts with a SELECT statement this can invoke a "database is locked" error if the SELECT statement is not exhausted or explicitly closed.

    This can lead to subtle "database is locked" bugs, even when a large timeout is set on the connection. Many, many people are affected by this bug (search the web for "python sqlite database is locked").

    The attached code demonstrates this bug and possible (unintuitive) fixes. The best workaround is to "explicitly" start a transaction in these cases by issuing a dummy DML statement. This seems very clumsy.

    My proposed fix is to implicitly open a transaction before all non-DDL statements (including SELECT statements), not just DML statements.

    If there won't be a fix soon, then at least the documentation should note this quirky behavior.

    @rhunter rhunter mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 23, 2016
    @rhunter
    Copy link
    Mannequin Author

    rhunter mannequin commented Mar 23, 2016

    duplicate of bpo-9924

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

    No branches or pull requests

    0 participants