[Django] #31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when USE_TZ is False.

50 views
Skip to first unread message

Django

unread,
May 19, 2020, 6:20:12 AM5/19/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------------+------------------------
Reporter: Carlton Gibson | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
The following test fails on 3.1a1.

> `USE_TZ`: If this is set to True, Django will use timezone-aware
datetimes internally. Otherwise, Django will use naive datetimes in local
time.

{{{
diff --git a/tests/forms_tests/field_tests/test_datetimefield.py
b/tests/forms_tests/field_tests/test_datetimefield.py
index f0e6ada3c5..ed035497d8 100644
--- a/tests/forms_tests/field_tests/test_datetimefield.py
+++ b/tests/forms_tests/field_tests/test_datetimefield.py
@@ -2,8 +2,8 @@ from datetime import date, datetime

from django.core.exceptions import ValidationError
from django.forms import DateTimeField
-from django.test import SimpleTestCase
-from django.utils.timezone import get_fixed_timezone, utc
+from django.test import SimpleTestCase, override_settings
+from django.utils.timezone import get_fixed_timezone, is_naive, utc


class DateTimeFieldTest(SimpleTestCase):
@@ -65,6 +65,12 @@ class DateTimeFieldTest(SimpleTestCase):
with self.subTest(value=value):
self.assertEqual(f.clean(value), expected_datetime)

+ @override_settings(USE_TZ=False)
+ def test_use_tz_false(self):
+ f = DateTimeField()
+ value = '2014-09-23T22:34Z'
+ self.assertTrue(is_naive(f.clean(value)))
+
def test_datetimefield_clean_invalid(self):
f = DateTimeField()
msg = "'Enter a valid date/time.'"
}}}

Expected behaviour is to return a naive datetime.

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

Django

unread,
May 19, 2020, 6:42:09 AM5/19/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
---------------------------------+------------------------------------

Reporter: Carlton Gibson | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by felixxm):

* cc: Claude Paroz (added)
* stage: Unreviewed => Accepted


Comment:

Regression in 1487f16f2d29c7aeaf48117d02a1d7bbeafa3d94.

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

Django

unread,
May 19, 2020, 9:43:47 AM5/19/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12938 PR]

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

Django

unread,
May 19, 2020, 3:17:39 PM5/19/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Repeating what I said on the PR. In my opinion, even if `USE_TZ` is False,
parsing a datetime including timezone information should really keep its
timezone. So I'd rather add an admonition to the docs.

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

Django

unread,
May 20, 2020, 6:15:40 AM5/20/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

So this caused a test failure on Django-Filter.

I've adjusted the test case there to account for the new behaviour.

https://github.com/carltongibson/django-filter/pull/1226

{{{
- @override_settings(USE_TZ=False)
def test_clean(self):
w = RangeWidget()
f = IsoDateTimeRangeField(widget=w)
- self.assertEqual(
- f.clean(['2015-01-01T10:30:01.123000+01:00',
'2015-01-10T08:45:02.345000+01:00']),
- slice(datetime(2015, 1, 1, 9, 30, 1, 123000),
- datetime(2015, 1, 10, 7, 45, 2, 345000)))
+ expected = slice(
+ datetime(2015, 1, 1, 9, 30, 1, 123000, tzinfo=timezone.utc),
+ datetime(2015, 1, 10, 7, 45, 2, 345000, tzinfo=timezone.utc)
+ )
+ actual = f.clean(['2015-01-01T10:30:01.123000+01:00',
'2015-01-10T08:45:02.345000+01:00'])
+ self.assertEqual(expected, actual)
}}}

Let's assume we'll go with the docs change.

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

Django

unread,
May 20, 2020, 6:20:07 AM5/20/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

Ok, I will create a PR for doc change.

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

Django

unread,
May 20, 2020, 6:34:16 PM5/20/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

I created a new [https://github.com/django/django/pull/12947 PR] to change
the release note and mention the behavior of forms.DateTimeField per
[https://github.com/django/django/pull/12938#issuecomment-631386529
Carlton comment].

--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:6>

Django

unread,
May 21, 2020, 2:23:08 PM5/21/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:7>

Django

unread,
May 21, 2020, 2:46:01 PM5/21/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Forms | Version: 3.1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"643207efaebbff4e7c3ebcbf9ca49fb6197137e1" 643207ef]:
{{{
#!CommitTicketReference repository=""
revision="643207efaebbff4e7c3ebcbf9ca49fb6197137e1"
Fixed #31608 -- Doc'd that form ISO 8601 datetime parsing always retains
tzinfo.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:8>

Django

unread,
May 21, 2020, 2:50:16 PM5/21/20
to django-...@googlegroups.com
#31608: forms.DateTimeField parses ISO 8601 datetime with offset as aware when
USE_TZ is False.
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Forms | Version: 3.1

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"a6c773aa869655e9dbb86ce9b500ddf1159c71b0" a6c773a]:
{{{
#!CommitTicketReference repository=""
revision="a6c773aa869655e9dbb86ce9b500ddf1159c71b0"
[3.1.x] Fixed #31608 -- Doc'd that form ISO 8601 datetime parsing always
retains tzinfo.

Backport of 643207efaebbff4e7c3ebcbf9ca49fb6197137e1 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:9>

Reply all
Reply to author
Forward
0 new messages