crate / crate-python

Python DB API client library for CrateDB, using HTTP.
https://cratedb.com/docs/python/
Apache License 2.0
79 stars 30 forks source link

Timestamp values: Remove the use of "naive" Python `datetime` objects #667

Closed amotl closed 3 hours ago

amotl commented 3 days ago

About

Python: Remove invocations to deprecated datetime.utcfromtimestamp(). World: Make datetime handling like it's 2024.

Summary

This is a possible BREAKING CHANGE about returned Python datetime objects:

Removed the use of "naive" Python datetime objects, i.e. instances without tzinfo attribute set.

Details

When no time_zone information is specified when creating a database connection or cursor, datetime objects will now use Coordinated Universal Time (UTC), like CrateDB is storing timestamp values in this format.

This update is coming from a deprecation of Python's datetime.utcfromtimestamp(), which is effectively also phasing out the use of "naive" timestamp objects in Python, in favor of using timezone-aware objects, also to represent datetimes in UTC. It may be a breaking change for some users of the library that don't expect to receive "aware" datetime objects from now on.

DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).