8000 gh-99392: Fix SQLite converter recipes by naglis · Pull Request #99393 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99392: Fix SQLite converter recipes #99393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix SQLite converter recipes
The converter functions are always passed a bytes object,
`datetime.date.fromisoformat` and `datetime.datetime.fromisoformat`
expect a `str`. In case of `convert_timestamp()` a cast to `int` is
missing.
  • Loading branch information
naglis committed Nov 11, 2022
commit 92a437035e2ba9638535a42911a33f3d925cc540
6 changes: 3 additions & 3 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2112,15 +2112,15 @@ This section shows recipes for common adapters and converters.

def convert_date(val):
"""Convert ISO 8601 date to datetime.date object."""
return datetime.date.fromisoformat(val)
return datetime.date.fromisoformat(val.decode())

def convert_datetime(val):
"""Convert ISO 8601 datetime to datetime.datetime object."""
return datetime.datetime.fromisoformat(val)
return datetime.datetime.fromisoformat(val.decode())

def convert_timestamp(val):
"""Convert Unix epoch timestamp to datetime.datetime object."""
return datetime.datetime.fromtimestamp(val)
return datetime.datetime.fromtimestamp(int(val))

sqlite3.register_converter("date", convert_date)
sqlite3.register_converter("datetime", convert_datetime)
Expand Down
0