Opened 3 years ago
Closed 3 years ago
#34202 closed Cleanup/optimization (wontfix)
Strict time zone name condition in PostgreSQL DatabaseWrapper.
| Reported by: | Alexander Ebral | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 4.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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
Change History (2)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
| Type: | Bug → Cleanup/optimization |
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.
This would be really clunky, e.g. all
UTC+Xtimezone would be consider equal toUTC.