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: Lib/sqlite3/dbapi2.py: convert_timestamp function failed to correctly parse timestamp
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Rayologist, erlendaasland, lemburg
Priority: normal Keywords: patch

Created on 2022-02-06 19:03 by Rayologist, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31169 open Rayologist, 2022-02-06 19:12
Messages (3)
msg412655 - (view) Author: Bo-wei Chen (Rayologist) * Date: 2022-02-06 19:03
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'
msg412828 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2022-02-08 10:54
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. In the meanwhile, I suggest taking a look at the linked issues.


[^1]: https://docs.python.org/3/library/sqlite3.html#default-adapters-and-converters
[^2]: bpo-19065
[^3]: bpo-26651
[^4]: bpo-45858
[^5]: https://discuss.python.org/t/fixing-sqlite-timestamp-converter-to-handle-utc-offsets/10985
msg412895 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2022-02-09 09:36
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.
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90820
2022-02-09 09:36:33lemburgsetmessages: + msg412895
2022-02-08 10:56:12erlendaaslandsetnosy: + lemburg
2022-02-08 10:54:25erlendaaslandsetmessages: + msg412828
2022-02-08 03:51:53ned.deilysetnosy: + erlendaasland
2022-02-06 19:12:38Rayologistsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29342
2022-02-06 19:03:59Rayologistcreate