Skip to content
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

gh-99392: Fix SQLite converter recipes #99393

Merged
merged 2 commits into from
Nov 12, 2022
Merged

gh-99392: Fix SQLite converter recipes #99393

merged 2 commits into from
Nov 12, 2022

Conversation

naglis
Copy link
Contributor

@naglis naglis commented Nov 11, 2022

gh-99392: 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.

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.
@erlend-aasland
Copy link
Contributor

Thanks for catching that. Could you add doctests for this, so we're sure the CI catches it if we mess it up (again)?

@erlend-aasland erlend-aasland self-assigned this Nov 11, 2022
@naglis
Copy link
Contributor Author

naglis commented Nov 12, 2022

@erlend-aasland I've added a doctest, not sure if it is any good.

Since the adapter for datetime.datetime is registered twice in the recipe (adapt_datetime_iso and adapt_datetime_epoch) I had to re-register them in each case so that the correct data is inserted. The re-registering does not feel nice.

You feedback would be appreciated.

@erlend-aasland
Copy link
Contributor

I've added a doctest [...]

Thanks!

I think simple unit-tests of the actual functions should be sufficient. So something like this for each adapter/converter pair:

assert adapter_fn(val) == foo
assert converter_fn(val) == bar

Since the adapter for datetime.datetime is registered twice in the recipe (adapt_datetime_iso and adapt_datetime_epoch) I had to re-register them in each case so that the correct data is inserted. The re-registering does not feel nice.

Yes, perhaps the docs are a little unclear about this. Those are just two examples, or variants, of datetime.datetime adapter/converters. One where the database representation is a number (UNIX epoch), and one where it is stored as an ISO-8601 string. We could make that fact a little bit more explicit.

@naglis
Copy link
Contributor Author

naglis commented Nov 12, 2022

I've added a doctest [...]

Thanks!

I think simple unit-tests of the actual functions should be sufficient. So something like this for each adapter/converter pair:

assert adapter_fn(val) == foo
assert converter_fn(val) == bar

@erlend-aasland thank you, I've simplified the doctest. As fromtimestamp() returns the local date/time it is tricky to assert on a pre-defined timestamp, so I've used the timestamp of the current time. Is that ok or maybe there are better ways to handle this?

@erlend-aasland
Copy link
Contributor

As fromtimestamp() returns the local date/time it is tricky to assert on a pre-defined timestamp, so I've used the timestamp of the current time. Is that ok or maybe there are better ways to handle this?

I'm fine with that. Thanks for adding the tests, and thanks again for the PR and the report!

@erlend-aasland erlend-aasland merged commit dfc1b17 into python:main Nov 12, 2022
@miss-islington
Copy link
Contributor

Thanks @naglis for the PR, and @erlend-aasland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 12, 2022
(cherry picked from commit dfc1b17)

Co-authored-by: naglis <827324+naglis@users.noreply.github.com>
@bedevere-bot
Copy link

GH-99419 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 12, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 12, 2022
(cherry picked from commit dfc1b17)

Co-authored-by: naglis <827324+naglis@users.noreply.github.com>
@bedevere-bot
Copy link

GH-99420 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 12, 2022
miss-islington added a commit that referenced this pull request Nov 12, 2022
(cherry picked from commit dfc1b17)

Co-authored-by: naglis <827324+naglis@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Nov 12, 2022
(cherry picked from commit dfc1b17)

Co-authored-by: naglis <827324+naglis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants