#35240: Django doesn't set Postgres timezone to UTC when using psycopg3
-----------------------------------------+------------------------
               Reporter:  Fabi           |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Uncategorized  |        Version:  5.0
               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              |
-----------------------------------------+------------------------
 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]: connections["default"].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]: connections["default"].timezone
 Out[5]: datetime.timezone.utc

 In [6]:
 connections["default"].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:
 -
 
https://github.com/django/django/blob/31314980be428c0ab8a6cf40cce0a0c17ead8ec6/django/db/backends/postgresql/base.py#L243-L246
 -
 
https://github.com/django/django/blob/31314980be428c0ab8a6cf40cce0a0c17ead8ec6/django/db/backends/postgresql/base.py#L349-L354
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35240>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018dc763fd58-bdcfcc83-eb4d-4da0-9147-7d0935cb85fb-000000%40eu-central-1.amazonses.com.

Reply via email to