This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [sqlite3] Fetching an empty value from date column raises ValueError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, erlendaasland, felixxm, frenzy
Priority: normal Keywords: patch

Created on 2021-04-06 18:29 by felixxm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25228 merged erlendaasland, 2021-04-06 19:12
Messages (7)
msg390357 - (view) Author: Mariusz Felisiak (felixxm) * Date: 2021-04-06 18:29
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] https://github.com/python/cpython/blob/50616223d1043f0f83534ffec38709439b8a49ab/Lib/sqlite3/dbapi2.py#L63-L64
msg390359 - (view) Author: Mariusz Felisiak (felixxm) * Date: 2021-04-06 18:40
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])
msg390365 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-06 19:23
Thanks for the report and the test case! :)

Regression was introduced by e161ec5dd7ba9355eb06757b9304019ac53cdf69, 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"".
msg390366 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-06 19:27
BTW, you might be interested in this bpo, Mariusz: bpo-43553
msg390367 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-06 19:37
> 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.
msg391058 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2021-04-14 11:18
New changeset 6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082 by Erlend Egeberg Aasland in branch 'master':
bpo-43752: Fix sqlite3 regression for zero-sized blobs with converters (GH-25228)
https://github.com/python/cpython/commit/6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082
msg391060 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2021-04-14 11:23
Thank you for the report and reproducer, Mariusz and thank you for the PR, Erlend.
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87918
2021-04-14 11:23:31berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg391060

stage: patch review -> resolved
2021-04-14 11:18:53berker.peksagsetmessages: + msg391058
2021-04-14 05:17:32frenzysetnosy: + frenzy
2021-04-06 19:37:33erlendaaslandsetmessages: + msg390367
2021-04-06 19:27:53erlendaaslandsetmessages: + msg390366
2021-04-06 19:23:43erlendaaslandsetmessages: + msg390365
2021-04-06 19:12:33erlendaaslandsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23965
2021-04-06 18:43:11erlendaaslandsettitle: Fetching an empty value from date column crashes on SQLite. -> [sqlite3] Fetching an empty value from date column raises ValueError
2021-04-06 18:40:41felixxmsetmessages: + msg390359
2021-04-06 18:29:34felixxmcreate