[Django] #34202: Strict time zone name condition in PostgreSQL DatabaseWrapper.

8 views
Skip to first unread message

Django

unread,
Dec 7, 2022, 11:23:30 AM12/7/22
to django-...@googlegroups.com
#34202: Strict time zone name condition in PostgreSQL DatabaseWrapper.
-------------------------------------+-------------------------------------
Reporter: Alexander | Owner: nobody
Ebral |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
DatabaseWrapper from
https://github.com/django/django/blob/main/django/db/backends/postgresql/base.py
in function ''ensure_timezone'' checks that
{{{
conn_timezone_name != timezone_name
}}}

in our PostgreSQL config timezone was set to 'Etc/UTC' and in django was
'UTC' (There is NO difference between UTC and Etc/UTC time zones:
https://stackoverflow.com/questions/14128574/is-there-a-difference-
between-the-utc-and-etc-utc-time-zones)
which led to many unnecessary

{{{
set time zone 'UTC'
}}}

queries.
Maybe we need to change this condition to some fuzzy form? Something like
this?:

{{{
conn_timezone_name not in timezone_name and timezone_name not in
conn_timezone_name
}}}

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

Django

unread,
Dec 7, 2022, 1:33:42 PM12/7/22
to django-...@googlegroups.com
#34202: Strict time zone name condition in PostgreSQL DatabaseWrapper.
-------------------------------------+-------------------------------------
Reporter: Alexander Ebral | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Mariusz Felisiak):

> Maybe we need to change this condition to some fuzzy form? Something
like this?:
>
> {{{
> conn_timezone_name not in timezone_name and timezone_name not in
conn_timezone_name
> }}}

This would be really clunky, e.g. all `UTC+X` timezone would be consider
equal to `UTC`.

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

Django

unread,
Dec 7, 2022, 11:41:58 PM12/7/22
to django-...@googlegroups.com
#34202: Strict time zone name condition in PostgreSQL DatabaseWrapper.
-------------------------------------+-------------------------------------
Reporter: Alexander Ebral | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* type: Bug => Cleanup/optimization
* resolution: => wontfix


Comment:

Maintaining list of time zone aliases in Django is not doable. Also, `UTC`
and `Etc/UTC` are not considered equal by `zoneinfo`:
{{{
>>> import zoneinfo
>>> z1 = zoneinfo.ZoneInfo("UTC")
>>> z2 = zoneinfo.ZoneInfo("Etc/UTC")
>>> z1 == z2
False
}}}
so I don't think there is much we can do in Django itself. I'd recommend
to use `UTC` in PostgreSQL or `Etc/UTC` in `settings.TIME_ZONE`.

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

Reply all
Reply to author
Forward
0 new messages