I'm importing data from csv to InfluxDB through a Django Rest Framework API endpoint.
The relevant part of the viewset:
if request.method == "PUT":
measurements = InputMeasurementSerializer(data=request.data, many=True)
measurements.is_valid(raise_exception=True)
The serializer:
class InputMeasurementSerializer(serializers.Serializer):
value = serializers.FloatField()
time = serializers.DateTimeField(input_formats=[
"%Y-%m-%d_%H:%M:%S", ...])
The input data is in the form of time value paires for every 15 minutes:
time,value
2021.04.11 00:00:00,0.172
2021.04.11 00:15:00,0.76
2021.04.11 00:30:00,0.678
2021.04.11 00:45:00,1.211
It works fine for all dates, except for the time values on the 28.03.2021 between 02:00-03:00 and on the 25.10.2020 between 02:00-03:00 it throws the exception: Invalid datetime for the timezone "Europe/Budapest".
Could be related to the time setting because of the daylight saving - but I don't see how exactly. Has anyone any clue what could be the problem here?
In my settings.py:
TIME_ZONE = 'Europe/Budapest'
USE_TZ = True
It indeed is because of the daylight savings, explained in the documentation
Even if your website is available in only one time zone, it’s still good practice to store data in UTC in your database. The main reason is Daylight Saving Time (DST). Many countries have a system of DST, where clocks are moved forward in spring and backward in autumn. If you’re working in local time, you’re likely to encounter errors twice a year, when the transitions happen. (The pytz documentation discusses these issues in greater detail.) This probably doesn’t matter for your blog, but it’s a problem if you over-bill or under-bill your customers by one hour, twice a year, every year. The solution to this problem is to use UTC in the code and use local time only when interacting with end users.