#32513: SQLite3 Backend Falsly claims SQLite does not support Timezone aware
DateTimes
-------------------------------------+-------------------------------------
               Reporter:  Arthur     |          Owner:  nobody
  Moore                              |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  datetime, timezone
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32513>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.62f68d66c051aa73cfeff20b8213eafd%40djangoproject.com.

Reply via email to