Opened 10 months ago
Last modified 10 months ago
#35240 closed Bug
Django doesn't set Postgres timezone to UTC when using psycopg3 — at Initial Version
Reported by: | Fabi | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | Fabi, Mariusz Felisiak, Florian Apolloner, Simon Charette | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Configuration uses USE_TZ=True
and database defaults to America/New_York
. I would expect the connection then being set to UTC, but it is not changed:
`
In [4]: connectionsdefault.cursor().connection.info.timezone
Out[4]: zoneinfo.ZoneInfo(key='America/New_York')
`
The wrapper and the psycopg3 timezone adapter both think its UTC though:
`
In [5]: connectionsdefault.timezone
Out[5]: datetime.timezone.utc
In [6]: connectionsdefault.cursor().connection.adapters.get_loader(TIMESTAMPTZ_OID, Format.TEXT).timezone
Out[6]: datetime.timezone.utc
`
Looking at the code I think the problem is that the adapter gets initialized with self.timezone
which then gets compared with self.timezone
later again, resulting in a no-op: