Opened 4 years ago

Last modified 4 years ago

#32513 closed Bug

SQLite3 Backend Falsly claims SQLite does not support Timezone aware DateTimes — at Version 1

Reported by: Arthur Moore Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords: datetime, timezone
Cc: Aymeric Augustin, udaykiran Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Arthur Moore)

If settings.USE_TZ is False, and I am using an SQLite3 database, I expect to be able to store a timezone aware DateTime Field.

Currently in the code, this raises a ValueError.

The SQLite documentation indicates that this is actually valid. In addition, if a database entry is modified with "-05:00" appended, then Django will correctly read from the database. Though attempting to immediately call save fails.

Example:
With a database where the first record has a timestamp with a timezone, and "settings.USE_TZ=False":

class DataPoint(models.Model):
    timestamp = models.DateTimeField()

d = DataPoint.objects.first()
print(d.timestamp)  # Successfully prints a datetime.datetime object with the correct tzinfo
d.save()  # Raises "ValueError: SQLite backend does not support timezone-aware datetimes when USE_TZ is False."

Why this matters:
We are storing scientific measurements where the customer needs to know the local day in which the data was recorded. This does not work by calculating their current timezone, as they care about the information as it was recorded not as it is now.

Our current approach is to leave "USE_TZ=True", store the timezone as an offset in minutes every time a data collection session takes place, and then combine them later. However, this means that we are either working around the ORM when selecting dates, or just not using it entirely.

Ideally, we would leave "USE_TZ=True", and only save the DataPoint with a timestamp, but that is a separate feature request.

Change History (1)

comment:1 by Arthur Moore, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top