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

Incorrect timezone handling when escaping a datetime-aware object #388

Open
krokoziabla opened this issue Aug 15, 2023 · 1 comment
Open

Comments

@krokoziabla
Copy link

Describe the bug
Suppose you have a table:

CREATE TABLE foo
(
    `timestamp` DateTime('UTC')
)

It contains some data. Let the maximum timestamp be 1546300800 (2019-01-01 00:00:00 UTC).
Suppose then that your CH installation resides in Moscow, so its TZ value is "Europe/Moscow"

Then you run the query using clickhouse-driver:

client.execute(
    "SELECT * FROM foo WHERE timestamp = %(timestamp)s",
    {"timestamp": datetime.datetime.fromisoformat("2019-01-01 00:00:00+00:00")})

But then a bad thing happens. This piece of code translates your timestamp to server's timezone Europe/Moscow and the resulting query SELECT * FROM foo WHERE timestamp = '2019-01-01 03:00:00' returns nothing, because as mentioned in CH's manual string values are treated in column's timezone, not server's one.

To Reproduce
See above

Expected behavior
I guess the driver has to deal with timezones more accurately. Treating timestamp string values in server's timezone may be correct if the type of column is not timezone-aware. But if the column has the explicit timezone set then it's obviously wrong to use the server's timezone for conversions.

Versions

  • clickhouse-driver 0.2.6
  • server 22.8.20.11
  • python 3.11
@hellais
Copy link

hellais commented Nov 20, 2023

For what it's work I am currently replacing the timezone information with None to workaround this bug.

It's probably quite important to fix this in light of the recent deprecation in python 3.12 of datetime.utcnow() which used to return time in utc without timezone information (see: https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated)

hellais added a commit to ooni/data that referenced this issue Nov 21, 2023
* Make utcnow() calls timezone aware
* Implement workardound for clickhouse bug mymarilyn/clickhouse-driver#388
* Implement more tests for range deletions
* Refactoring of get_prev_range functions
* Fix problem in experiment result generation
hellais added a commit to ooni/data that referenced this issue Nov 21, 2023
* Make utcnow() calls timezone aware
* Implement workardound for clickhouse bug mymarilyn/clickhouse-driver#388
* Implement more tests for range deletions
* Refactoring of get_prev_range functions
* Fix problem in experiment result generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants