#32513: SQLite3 Backend Falsly claims SQLite does not support Timezone aware
DateTimes
-------------------------------------+-------------------------------------
Reporter: Arthur Moore | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: datetime, timezone | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Arthur Moore:
Old description:
> 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
> [https://github.com/django/django/blob/b19041927883123e0147d80b820ddabee9a716f6/django/db/backends/sqlite3/operations.py#L236
> the code], this raises a ValueError.
>
> The SQLite [https://sqlite.org/lang_datefunc.html 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(max_length=255)
>
> 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.
New description:
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
[https://github.com/django/django/blob/b19041927883123e0147d80b820ddabee9a716f6/django/db/backends/sqlite3/operations.py#L236
the code], this raises a ValueError.
The SQLite [https://sqlite.org/lang_datefunc.html 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32513#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.0e959775c0ea1d7506b838ee84662b9b%40djangoproject.com.