From 6b37eb63e1fd13100f6d31b9ac5e037ffce2dcd3 Mon Sep 17 00:00:00 2001 From: Ian Fisher Date: Sun, 24 Oct 2021 08:52:31 -0400 Subject: [PATCH 1/2] bpo-45335: Add note to `sqlite3` docs about "timestamp" converter --- Doc/library/sqlite3.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index eaea7ae390b972..292cbc5d7da0a5 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -1049,6 +1049,17 @@ If a timestamp stored in SQLite has a fractional part longer than 6 numbers, its value will be truncated to microsecond precision by the timestamp converter. +.. warning:: + + The "timestamp" converter ignores UTC offsets in the database and always + returns a naive :class:`datetime.datetime` object, so if you read a timestamp + from the database with converters enabled and then write it back, any UTC + offset will be lost. + + If you need to preserve UTC offsets in timestamps, then either leave + converters disabled, or register your own offset-aware converter with + :func:`register_converter` to override the default one. + .. _sqlite3-controlling-transactions: From e8572f757b3387900e059dffa538ebd5b299a6b3 Mon Sep 17 00:00:00 2001 From: Ian Fisher Date: Thu, 28 Oct 2021 17:22:32 -0400 Subject: [PATCH 2/2] Address comments from reviewers --- Doc/library/sqlite3.rst | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 292cbc5d7da0a5..067306ce47f436 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -1049,17 +1049,12 @@ If a timestamp stored in SQLite has a fractional part longer than 6 numbers, its value will be truncated to microsecond precision by the timestamp converter. -.. warning:: - - The "timestamp" converter ignores UTC offsets in the database and always - returns a naive :class:`datetime.datetime` object, so if you read a timestamp - from the database with converters enabled and then write it back, any UTC - offset will be lost. - - If you need to preserve UTC offsets in timestamps, then either leave - converters disabled, or register your own offset-aware converter with - :func:`register_converter` to override the default one. +.. note:: + The default "timestamp" converter ignores UTC offsets in the database and + always returns a naive :class:`datetime.datetime` object. To preserve UTC + offsets in timestamps, either leave converters disabled, or register an + offset-aware converter with :func:`register_converter`. .. _sqlite3-controlling-transactions: