Fix sqlite timezone-naive adapter recipe · Issue #131825 · python/cpython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Fix sqlite timezone-naive adapter recipe #131825

Open
@drf5n

Description

@drf5n

Documentation

This recipe for an adapter does not work as advertised:

   def adapt_datetime_iso(val):
       """Adapt datetime.datetime to timezone-naive ISO 8601 date."""
       return val.isoformat()

from: https://github.com/erlend-aasland/cpython/blob/a3711d1541c1b7987941b41d2247f87dae347117/Doc/library/sqlite3.rst?plain=1#L2287-L2289
or https://docs.python.org/3/library/sqlite3.html#sqlite3-adapter-converter-recipes

If the argument has a timezone, it will produce a timezone-aware result, contrary to its documentation
Consider the difference between these:

import datetime
print(datetime.datetime.now(datetime.timezone.utc).isoformat())
print(datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).isoformat())

"""
2025-03-28T08:41:09.240880+00:00
2025-03-28T08:41:09.241046
"""

The recipe should instead be like this:

   def adapt_datetime_iso(val):
       """Adapt datetime.datetime to timezone-naive ISO 8601 date."""
       return val.replace(tzinfo=None).isoformat()

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasytopic-sqlite3type-bugAn unexpected behavior, bug, or error

    Projects

    Status

    TODO: Docs

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.