#35267: DateTimeField does not seem to be translated back to the local timezone on
data retrieval on Postgres
-------------------------------------+-------------------------------------
Reporter: Josh | Owner: nobody
Smeaton |
Type: | Status: new
Uncategorized |
Component: Database | Version: 5.0
layer (models, ORM) | Keywords: orm datetimefield
Severity: Normal | timezones
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/#postgresql
> The PostgreSQL backend stores datetimes as timestamp with time zone. In
practice, this means it converts datetimes from the connection’s time zone
to UTC on storage, and from UTC to the connection’s time zone on
retrieval.
This wording seems to suggest that Django DateTimeField will return
datetimes with the tzinfo set to `settings.TIME_ZONE`, but that's not what
I observe. All data returned is in utc.
Am I mistaking the blurb on the timezone support docs?
https://github.com/django/django/blob/f5ed4306bbfd2e5543dd02cf5a22326a29253cdf/django/db/models/fields/__init__.py#L1594
defines a `to_python` which will make a datetime aware, but that's only
used by the serialization framework.
I would expect a `from_db_value` to convert the returned value from `utc`
to the timezone defined by settings.TIME_ZONE.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35267>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.