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

Lib/sqlite3/dbapi2.py: convert_timestamp function failed to correctly parse timestamp #90820

Closed
Rayologist mannequin opened this issue Feb 6, 2022 · 5 comments
Closed
Labels
3.9 only security fixes stdlib Python modules in the Lib dir topic-sqlite3 type-bug An unexpected behavior, bug, or error

Comments

@Rayologist
Copy link
Mannequin

Rayologist mannequin commented Feb 6, 2022

BPO 46662
Nosy @malemburg, @erlend-aasland, @Rayologist
PRs
  • bpo-46662: Fix convert_timestamp function that failed to correctly parse timestamp #31169
  • 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 = None
    created_at = <Date 2022-02-06.19:03:59.534>
    labels = ['type-bug', 'library', '3.9']
    title = 'Lib/sqlite3/dbapi2.py: convert_timestamp function failed to correctly parse timestamp'
    updated_at = <Date 2022-02-09.09:36:33.984>
    user = 'https://github.com/Rayologist'

    bugs.python.org fields:

    activity = <Date 2022-02-09.09:36:33.984>
    actor = 'lemburg'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-02-06.19:03:59.534>
    creator = 'Rayologist'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46662
    keywords = ['patch']
    message_count = 3.0
    messages = ['412655', '412828', '412895']
    nosy_count = 3.0
    nosy_names = ['lemburg', 'erlendaasland', 'Rayologist']
    pr_nums = ['31169']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46662'
    versions = ['Python 3.9']

    @Rayologist
    Copy link
    Mannequin Author

    Rayologist mannequin commented Feb 6, 2022

    convert_timestamp function in Lib/sqlite3/dbapi2.py fails to parse a timestamp correctly, if it does not have microseconds but comes with timezone information, e.g. b"2022-02-01 16:09:35+00:00"

    Traceback:

    Traceback (most recent call last):
      File "/Users/user/Desktop/test.py", line 121, in <module>
        convert_timestamp(b"2022-02-01 16:09:35+00:00")
      File "/Users/user/Desktop/test.py", line 112, in convert_timestamp
        hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
    ValueError: invalid literal for int() with base 10: b'35+00'

    @Rayologist Rayologist mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 6, 2022
    @erlend-aasland
    Copy link
    Contributor

    erlend-aasland commented Feb 8, 2022

    The sqlite3 timestamp converter is buggy, as already noted in the docs1. Adding timezone support is out of the question2345, but fixing it to be able to discard any attached timezone info _may_ be ok; at first sight, I don't see how this could break existing applications (like, for example adding time zone support could do). I need to think it through. In the meanwhile, I suggest taking a look at the linked issues.

    Footnotes

    1. https://docs.python.org/3/library/sqlite3.html#default-adapters-and-converters

    2. sqlite3 timestamp adapter chokes on timezones #63265

    3. Deprecate register_adapter() and register_converter() in sqlite3 #70838

    4. Deprecate default converters in sqlite3 #90016

    5. https://discuss.python.org/t/fixing-sqlite-timestamp-converter-to-handle-utc-offsets/10985

    @malemburg
    Copy link
    Member

    On 08.02.2022 11:54, Erlend E. Aasland wrote:

    The sqlite3 timestamp converter is buggy, as already noted in the docs[^1]. Adding timezone support is out of the question[^2][^3][^4][^5], but fixing it to be able to discard any attached timezone info _may_ be ok; at first sight, I don't see how this could break existing applications (like, for example adding time zone support could do). I need to think it through.

    I think it's better to deprecate these converters and let users implement
    their own.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland
    Copy link
    Contributor

    I think it's better to deprecate these converters and let users implement their own.

    Suggesting to deprecate the built-in converters when 3.12 dev opens up.

    @erlend-aasland
    Copy link
    Contributor

    As per discussion on Discourse, we will deprecate the built-in, default adapters and converters. Thus, this issue is now superseded by gh-90016.

    @erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2022
    @erlend-aasland erlend-aasland moved this from Done to Discarded in sqlite3 issues May 21, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir topic-sqlite3 type-bug An unexpected behavior, bug, or error
    Projects
    Status: Discarded
    Development

    No branches or pull requests

    2 participants