ooni / backend

Everything related to OONI backend infrastructure: ooni/api, ooni/pipeline, ooni/sysadmin, collector, bouncers and test-helpers
BSD 3-Clause "New" or "Revised" License
48 stars 28 forks source link

backend: investigate potential issue with not using timezone aware datetime #774

Open hellais opened 7 months ago

hellais commented 7 months ago

As far as I understand it, we are currently not using timezone aware datetime objects in all of the backend code.

Python 3.12 has deprecated the utcnow() function and it's going to be removed in future versions: https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated.

In 31 places we are calling the since python 3.12 deprecated datetime.utcnow() function:

$ rg --no-filename utcnow | wc -l
      31

While we are at it we should possibly consider if there are other issues related to our use of non-timezone aware functions. For example the clickhouse tables are not specified with the UTC timezone so they will have the timezone set of wherever the machine is run on.

Which is OK since we run all our backend infrastructure on machines that use the UTC timezone, but if that ever changes (maybe because we use some cloud or we are running the code on our laptop) this is going to be a very confusing bug to investigate.

To make things even more annoying, the clickhouse driver we use doesn't work with timezones properly: https://github.com/mymarilyn/clickhouse-driver/issues/388, so we can't easily just switch to using timezone aware functions.

Anyways this issue it to remember about it and think about it when we decide to pick up some refactoring of backend.