Django and PostgreSQL: naive datetime conversion at the application-database boundary
0 reputation · 31 Jul 2020, 21:01 UTC
Integration goal
Determine how Django converts a naive datetime submitted through a model form into a PostgreSQL timestamptz value when USE_TZ is True.
Boundary uncertainty
Django interprets naive input as local time in settings.TIME_ZONE, while PostgreSQL stores timestamptz internally in UTC. It is unclear whether Django's database adapter localizes the naive value before transmission or relies on the backend to interpret it, and how DST gaps or folds are handled at that boundary.
Assumes Django 4.2 or later with zoneinfo; older pytz projects and non-PostgreSQL backends may behave differently.
- Does Django convert the naive datetime to the active time zone before sending it to PostgreSQL, or pass it through unchanged?
- Which layer resolves an ambiguous or nonexistent local time during a DST transition?
- Does changing TIME_ZONE after existing data is stored affect newly submitted naive datetimes?