Repository navigation
Conversation
Don't rely on sqlite3's default datetime adapter and converter, which are deprecated since Python 3.12 and fail to parse timestamps without microseconds. Rows written by older versions still read fine. Fixes mvantellingen#1507
uninformedpowerpoints-ship-it
left a comment
There was a problem hiding this comment.
Windows cache upgrade check for 1be9eed (CPython 3.12.16 x64, SQLite 3.53.1), run with Codex.
Zeep 4.2.1 and 4.3.3 each wrote an on-disk cache through SqliteCache.add(), with one whole-second timestamp and one fractional-second timestamp per file. On main (1b7072c), reading the whole-second entry from 4.3.3 reproduced #1507: ValueError: invalid literal for int() with base 10: b'00+00'. The other three entries were readable.
On the PR, all four entries returned their original bytes at exactly the 60-second timeout and returned None one microsecond later. Both database files were byte-identical after the reads. The PR read both timestamp formats (with and without the UTC offset) with deprecation warnings treated as errors.
python -m pytest -q tests/test_cache.py passed all 17 tests on the PR. The only warning came from the existing pytest.yield_fixture in tests/conftest.py.
Fixes #1507.
SqliteCachenow writes the timestamp as ISO text itself and parses it withdatetime.fromisoformatinget(), instead of going through sqlite3's default adapter and converter. That gets rid of the deprecation warnings on 3.12+ and fixes theValueErrorwhen an entry is cached on a whole second. Existing cache files keep working, sincefromisoformatreads what the old adapter wrote, with or without the UTC offset.Notes
I added tests for the whole-second case, for rows in the old formats, and one that checks no sqlite3 deprecation warning is raised. The suite passes on 3.10 and 3.15. This is independent of #1506.