[Django] #32992: Trunc query different on Django 3.2 due to change in `_get_timezone_name()`

30 views
Skip to first unread message

Django

unread,
Aug 6, 2021, 12:27:30 AM8/6/21
to django-...@googlegroups.com
#32992: Trunc query different on Django 3.2 due to change in `_get_timezone_name()`
-----------------------------------------+------------------------
Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When using a time zone of "Etc/GMT-10" (or similar) for a Trunc class
`tzinfo`, it appears there's a different behavior as of Django 3.2 in the
resulting database query. I think it's due to a change in the return value
of `timezone._get_timezone_name()` that's called by the `TimezoneMixin`.

On Django 3.1 the `TimezoneMixin` method `get_tzname()` returns "+10" for
a "Etc/GMT-10" time zone after calling
[https://github.com/django/django/blob/febc980e89591ffdc6df86cbeac13d7dfd89876e/django/utils/timezone.py#L71
_get_timezone_name()]. This later becomes "-10" in the resulting query due
to the return value of `_prepare_tzname_delta()` of the Postgres
`DatabaseOperations` class, i.e. the time zone 10 hours east from UTC.

{{{
SELECT ... DATE_TRUNC(\'day\', "my_model"."start_at" AT TIME ZONE \'-10\')
AS "date" ...
}}}

On Django 3.2 the `TimezoneMixin` method `get_tzname()` returns
"Etc/GMT-10" for a "Etc/GMT-10" time zone after calling
[https://github.com/django/django/blob/f18da11b8a7a4f9b80798704085b37194a3627fd/django/utils/timezone.py#L76
_get_timezone_name()]. This later, incorrectly, becomes "Etc/GMT+10" in
the resulting query due to the return value of `_prepare_tzname_delta()`
of the Postgres `DatabaseOperations` class, i.e. the time zone 10 hours
west from UTC, which is the opposite direction from the behavior in Django
3.1.

{{{
SELECT ... DATE_TRUNC(\'day\', "my_model"."start_at" AT TIME ZONE
\'Etc/GMT+10\') AS "date" ...
}}}

{{{
# Django 3.1

>>> timezone._get_timezone_name(pytz.timezone("Etc/GMT-10"))
'+10'

# Django 3.2

>>> timezone._get_timezone_name(pytz.timezone("Etc/GMT-10"))
'Etc/GMT-10'
}}}

The above is the same when using Python's `zoneinfo.ZoneInfo()` too.

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

Django

unread,
Aug 6, 2021, 1:20:57 AM8/6/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------

Reporter: James Beith | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
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 Mariusz Felisiak):

* cc: Carlton Gibson, Paul Ganssle (added)
* component: Uncategorized => Database layer (models, ORM)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

Regression in 10d126198434810529e0220b0c6896ed64ca0e88.
Reproduced at 4fe3774c729f3fd5105b3001fe69a70bdca95ac3.

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

Django

unread,
Aug 6, 2021, 2:11:37 AM8/6/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: tigicion
Type: Bug | Status: assigned

Component: Database layer | Version: 3.2
(models, ORM) |
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 tigicion):

* owner: nobody => tigicion
* status: new => assigned


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

Django

unread,
Aug 7, 2021, 10:17:29 AM8/7/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: (none)
Type: Bug | Status: new

Component: Database layer | Version: 3.2
(models, ORM) |
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 tigicion):

* owner: tigicion => (none)
* status: assigned => new


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

Django

unread,
Aug 20, 2021, 1:43:09 PM8/20/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: (none)
Type: Bug | Status: new

Component: Database layer | Version: 3.2
(models, ORM) |
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
-------------------------------------+-------------------------------------

Comment (by Alan):

This problem is also affecting MySQL, the timezone "Etc/GMT-10" is
returning "-10" instead of "-10:00". #33037

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

Django

unread,
Aug 22, 2021, 4:18:55 AM8/22/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: assigned

Component: Database layer | Version: 3.2
(models, ORM) |
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 Carlton Gibson):

* owner: (none) => Carlton Gibson


* status: new => assigned


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

Django

unread,
Aug 24, 2021, 5:33:25 AM8/24/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
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
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

[https://github.com/django/django/pull/14792 PR] — Alan and James, it
would be good if you could confirm this addresses your issues.

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

Django

unread,
Aug 24, 2021, 5:33:32 AM8/24/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
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 Carlton Gibson):

* has_patch: 0 => 1


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

Django

unread,
Aug 24, 2021, 9:17:10 PM8/24/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
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 James Beith):

This fixes the original issue I encountered, thanks!

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

Django

unread,
Aug 30, 2021, 4:14:19 AM8/30/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
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 Mariusz Felisiak):

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 30, 2021, 4:46:33 AM8/30/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"cbba49971bbbbe3e8c6685e4ce6ab87b1187ae87" cbba499]:
{{{
#!CommitTicketReference repository=""
revision="cbba49971bbbbe3e8c6685e4ce6ab87b1187ae87"
Fixed #32992 -- Restored offset extraction for fixed offset timezones.

Regression in 10d126198434810529e0220b0c6896ed64ca0e88.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32992#comment:10>

Django

unread,
Aug 30, 2021, 4:46:51 AM8/30/21
to django-...@googlegroups.com
#32992: Reverse time zone conversion in Trunc()/Extract() database functions.
-------------------------------------+-------------------------------------
Reporter: James Beith | Owner: Carlton
| Gibson
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"fe3a854e1de2753ad6fa78a8584f85186092f801" fe3a854e]:
{{{
#!CommitTicketReference repository=""
revision="fe3a854e1de2753ad6fa78a8584f85186092f801"
[3.2.x] Fixed #32992 -- Restored offset extraction for fixed offset
timezones.

Regression in 10d126198434810529e0220b0c6896ed64ca0e88.

Backport of cbba49971bbbbe3e8c6685e4ce6ab87b1187ae87 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32992#comment:11>

Reply all
Reply to author
Forward
0 new messages