Skip to content

[sqlite3] simplify "isolation level" #89675

Closed

Description

@erlend-aasland
BPO 45512
Nosy @corona10, @erlend-aasland
PRs
  • bpo-45512: Simplify isolation_level handling in sqlite3 #29053
  • bpo-45512: Raise exception if sqlite3.Connection.__init__ is called with bad isolation level #29561
  • bpo-45512: Simplify manage isolation level #29562
  • bpo-45512: Extend sqlite3 test suite regarding isolation levels #29576
  • bpo-45512: Use Argument Clinic to set sqlite3 isolation level #29593
  • 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 2021-11-18.10:28:27.776>
    created_at = <Date 2021-10-18.12:59:11.039>
    labels = ['extension-modules', '3.11']
    title = '[sqlite3] simplify "isolation level"'
    updated_at = <Date 2021-11-18.10:28:27.775>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-11-18.10:28:27.775>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-11-18.10:28:27.776>
    closer = 'erlendaasland'
    components = ['Extension Modules']
    creation = <Date 2021-10-18.12:59:11.039>
    creator = 'erlendaasland'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45512
    keywords = ['patch']
    message_count = 12.0
    messages = ['404182', '405816', '405936', '406342', '406347', '406350', '406463', '406467', '406468', '406469', '406522', '406529']
    nosy_count = 2.0
    nosy_names = ['corona10', 'erlendaasland']
    pr_nums = ['29053', '29561', '29562', '29576', '29593']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue45512'
    versions = ['Python 3.11']

    Activity

    1. erlend-aasland commented on Oct 18, 2021

      @erlend-aasland
      ContributorAuthor

      While working on bpo-45126 / #72414 (and while working on the AC conversion, bpo-40956), I've been slightly frustrated on the implementation of sqlite3 "isolation level". The code is messy, and we've got two connection members that carry pretty much the same type of information (self->isolation_level, and self->begin_statement).

      I would like to make the following enhancements:

      • merge 'isolation_level' and 'begin_statement' members in some kind of way
      • split pysqlite_connection_set_isolation_level():
        + one method for parsing and storing the 'isolation_level' member
        + one method for carrying out any needed SQLite API operation

      This should result in a cleaner connection __init__() method.

      Another slightly related performance enhancement could be to cache the "begin" (and "commit") statements as sqlite3_stmt pointers on the connection object, but that is a digression.

    2. corona10 commented on Nov 5, 2021

      @corona10
      Member

      Hmm, now I understood what you intended,
      The code was hard to read without knowing the condition of the begin_statement.
      Would this be a trade-off in terms of code readability?

    3. erlend-aasland commented on Nov 8, 2021

      @erlend-aasland
      ContributorAuthor

      IMO, #73239 improves readability, mainly because of these factors:

      • Argument Clinic now takes care of the ref count dance, and as a bonus, it is more self-documenting (stating clearly that it accepts str and None)
      • Begin statement validation has been refactored out, which IMO helps understanding how isolation level and begin statement is related
      • The isolation level setter is now greatly simplified; it fits well in a screenful, there are fewer ref count dances
      • Using get_begin_statement() is much less noisier than the previous string compare code in pysqlite_connection_set_isolation_level()

      The only thing that still bugs me is the "magical" 6 byte offset needed to convert between isolation level and begin statement. Perhaps a set of conversion functions would make it more readable.

    4. corona10 commented on Nov 15, 2021

      @corona10
      Member

      New changeset b567b9d by Erlend Egeberg Aasland in branch 'main':
      bpo-45512: Simplify isolation_level handling in sqlite3 (GH-29053)
      b567b9d

    5. erlend-aasland commented on Nov 15, 2021

      @erlend-aasland
      ContributorAuthor

      Need to amend #73239, so I'm opening until the fix is merged.

    6. corona10 commented on Nov 15, 2021

      @corona10
      Member

      New changeset 822c3dc by Erlend Egeberg Aasland in branch 'main':
      bpo-45512: Raise exception if sqlite3.Connection.__init__ is called with bad isolation level (bpo-29561)
      822c3dc

    7. corona10 commented on Nov 17, 2021

      @corona10
      Member

      New changeset 5f9247e by Erlend Egeberg Aasland in branch 'main':
      bpo-45512: Extend sqlite3 test suite regarding isolation levels (GH-29576)
      5f9247e

    8. corona10 commented on Nov 17, 2021

      @corona10
      Member

      @erlendaasland

      Now we close this issue right?

    9. corona10 commented on Nov 17, 2021

      @corona10
      Member

      New changeset e002bbc by Dong-hee Na in branch 'main':
      bpo-45512: Simplify manage isolation level (GH-29562)
      e002bbc

    10. erlend-aasland commented on Nov 17, 2021

      @erlend-aasland
      ContributorAuthor

      Now we close this issue right?

      Not yet ;) I have an AC tweak I'd like to add. Wait for a PR anytime soon.

    11. corona10 commented on Nov 18, 2021

      @corona10
      Member

      New changeset 0920b61 by Erlend Egeberg Aasland in branch 'main':
      bpo-45512: Use Argument Clinic to set sqlite3 isolation level (GH-29593)
      0920b61

    12. erlend-aasland commented on Nov 18, 2021

      @erlend-aasland
      ContributorAuthor

      Thanks for reviews and improvements, Dong-hee :)

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions