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

[sqlite3] Fetching an empty value from date column raises ValueError #87918

Closed
felixxm mannequin opened this issue Apr 6, 2021 · 7 comments
Closed

[sqlite3] Fetching an empty value from date column raises ValueError #87918

felixxm mannequin opened this issue Apr 6, 2021 · 7 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@felixxm
Copy link
Mannequin

felixxm mannequin commented Apr 6, 2021

BPO 43752
Nosy @berkerpeksag, @frenzymadness, @erlend-aasland, @felixxm
PRs
  • bpo-43752: Fix sqlite3 regression for zero-sized blobs with converters #25228
  • 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-04-14.11:23:31.401>
    created_at = <Date 2021-04-06.18:29:34.231>
    labels = ['type-bug', 'library', '3.10']
    title = '[sqlite3] Fetching an empty value from date column raises ValueError'
    updated_at = <Date 2021-04-14.11:23:31.401>
    user = 'https://github.com/felixxm'

    bugs.python.org fields:

    activity = <Date 2021-04-14.11:23:31.401>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-14.11:23:31.401>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2021-04-06.18:29:34.231>
    creator = 'felixxm'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43752
    keywords = ['patch']
    message_count = 7.0
    messages = ['390357', '390359', '390365', '390366', '390367', '391058', '391060']
    nosy_count = 4.0
    nosy_names = ['berker.peksag', 'frenzy', 'erlendaasland', 'felixxm']
    pr_nums = ['25228']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43752'
    versions = ['Python 3.10']

    @felixxm
    Copy link
    Mannequin Author

    felixxm mannequin commented Apr 6, 2021

    We noticed a regression in Python3.10.0a7 (it works properly in Python3.10.0a6) when running Django's test suite. convert_date()[1] is called and crashes when fetching an empty value from date column on SQLite:

    File "python3.10/lib/sqlite3/dbapi2.py", line 64, in convert_date
    return datetime.date(*map(int, val.split(b"-")))
    ValueError: invalid literal for int() with base 10: b''

    I will bisect a regression and submit PR.

    [1]

    def convert_date(val):
    return datetime.date(*map(int, val.split(b"-")))

    @felixxm felixxm mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 6, 2021
    @felixxm
    Copy link
    Mannequin Author

    felixxm mannequin commented Apr 6, 2021

    A regression test:

        def test_convert_null_date(self):
            con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
            cur = con.cursor()
            cur.execute("CREATE TABLE t (x DATE NULL)")
            cur.execute("INSERT INTO t (x) VALUES (NULL)")
            cur.execute("SELECT * FROM t")
            values = [x[0] for x in cur.fetchall()]
            self.assertEqual(values, [None])

    @erlend-aasland erlend-aasland changed the title Fetching an empty value from date column crashes on SQLite. [sqlite3] Fetching an empty value from date column raises ValueError Apr 6, 2021
    @erlend-aasland erlend-aasland changed the title Fetching an empty value from date column crashes on SQLite. [sqlite3] Fetching an empty value from date column raises ValueError Apr 6, 2021
    @erlend-aasland
    Copy link
    Contributor

    Thanks for the report and the test case! :)

    Regression was introduced by e161ec5, where it was assumed that the handling of zero-sized blobs should be consistent. Unfortunately, the handling of zero-sized blobs is not consistent. Zero-sized blobs _with_ converters must return None; zero-sized blobs _without_ converters must return b"".

    @erlend-aasland
    Copy link
    Contributor

    BTW, you might be interested in this bpo, Mariusz: bpo-43553

    @erlend-aasland
    Copy link
    Contributor

    Zero-sized blobs _with_ converters must return None; zero-sized blobs _without_ converters must return b"".

    Maybe the docs should be updated to reflect this inconsistency.

    @berkerpeksag
    Copy link
    Member

    New changeset 6f1e8cc by Erlend Egeberg Aasland in branch 'master':
    bpo-43752: Fix sqlite3 regression for zero-sized blobs with converters (GH-25228)
    6f1e8cc

    @berkerpeksag
    Copy link
    Member

    Thank you for the report and reproducer, Mariusz and thank you for the PR, Erlend.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants