[Django] #26842: SQLite3 backend raises error when reading tz-aware datetime value

7 views
Skip to first unread message

Django

unread,
Jul 5, 2016, 8:19:29 PM7/5/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
----------------------------------------------+--------------------
Reporter: ryochiji | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------------------+--------------------
When a DateTimeField in a sqlite3 backend contains a timezone-aware value,
an error is raised when reading the object. This seems to happen because
[https://github.com/django/django/blob/stable/1.9.x/django/db/backends/sqlite3/operations.py#L215
convert_datetimefield_value] doesn't check to make sure the value is naive
before passing to make_aware, which
[https://github.com/django/django/blob/stable/1.9.x/django/utils/timezone.py#L367
raises an error if it receives a tz-aware value].

--
Ticket URL: <https://code.djangoproject.com/ticket/26842>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 5, 2016, 8:52:57 PM7/5/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
-------------------------------------+-------------------------------------
Reporter: ryochiji | Owner:
| kennethyang404
Type: Uncategorized | Status: assigned
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kennethyang404):

* owner: nobody => kennethyang404
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26842#comment:1>

Django

unread,
Jul 5, 2016, 9:17:50 PM7/5/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
-------------------------------------+-------------------------------------
Reporter: ryochiji | Owner:
| kennethyang404
Type: Uncategorized | Status: assigned
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by kennethyang404):

SQLite doesn't support tz-aware datetimes.

--
Ticket URL: <https://code.djangoproject.com/ticket/26842#comment:2>

Django

unread,
Jul 5, 2016, 9:18:15 PM7/5/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
-------------------------------------+-------------------------------------
Reporter: ryochiji | Owner:
| kennethyang404
Type: Uncategorized | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kennethyang404):

* status: assigned => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/26842#comment:3>

Django

unread,
Jul 6, 2016, 7:01:32 PM7/6/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
-------------------------------------+-------------------------------------
Reporter: ryochiji | Owner:
| kennethyang404
Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by ryochiji):

I have a bit of code (a unit test) that works in Django 1.7 and 1.8, but
breaks in 1.9. Both 1.7 and 1.8 check the value to see if it's tz-naive
([https://github.com/django/django/blob/stable/1.7.x/django/db/backends/sqlite3/base.py#L52
here] and
[https://github.com/django/django/blob/stable/1.8.x/django/db/backends/sqlite3/utils.py#L9
here]) but not 1.9. Am I to interpret that this change in behavior is by
design?

--
Ticket URL: <https://code.djangoproject.com/ticket/26842#comment:4>

Django

unread,
Jul 6, 2016, 8:14:20 PM7/6/16
to django-...@googlegroups.com
#26842: SQLite3 backend raises error when reading tz-aware datetime value
-------------------------------------+-------------------------------------
Reporter: ryochiji | Owner:
| kennethyang404
Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by kennethyang404):

I think an exception is the desired behavior when trying to read a tz-
aware value from a db that doesn't support timezone. Here are more info I
found about this change:
[https://github.com/django/django/blob/ec186572e6cfde4cd4bc1491ff552c5d32211d9f/docs/releases/1.9.txt#L421
here] and
[https://github.com/django/django/blob/ec186572e6cfde4cd4bc1491ff552c5d32211d9f/docs/releases/1.9.txt#L316
here]

Replying to [comment:4 ryochiji]:


> I have a bit of code (a unit test) that works in Django 1.7 and 1.8, but
breaks in 1.9. Both 1.7 and 1.8 check the value to see if it's tz-naive
([https://github.com/django/django/blob/stable/1.7.x/django/db/backends/sqlite3/base.py#L52
here] and
[https://github.com/django/django/blob/stable/1.8.x/django/db/backends/sqlite3/utils.py#L9
here]) but not 1.9. Am I to interpret that this change in behavior is by
design?

--
Ticket URL: <https://code.djangoproject.com/ticket/26842#comment:5>

Reply all
Reply to author
Forward
0 new messages