Why does my Django ORM query with naive datetimes return the same results as a PostgreSQL query with time zone-aware datetimes?
I'm using Django to filter reservations based on a date range with naive datetimes. My Django ORM query is:
start_d_date_naive = "2024-11-3 00:00"
end_d_date_naive = "2024-11-3 23:59"
reserve_naive = Reservations.objects.filter(
updated_at__range=(start_d_date_naive, end_d_date_naive), status="canceled"
)
This translates to the following SQL query:
SELECT * FROM "consultant_reservations"
WHERE "consultant_reservations"."status" = 'canceled'
AND "consultant_reservations"."updated_at" BETWEEN '2024-11-03 00:00:00' AND '2024-11-03 23:59:00'
However, the results are the same as if I had run this query directly in PostgreSQL:
SELECT * FROM "consultant_reservations"
WHERE updated_at BETWEEN '2024-11-03 00:00:00+03:30' AND '2024-11-03 23:59:00+03:30'
AND status='canceled';
Why does the Django ORM query with naive datetimes return the same results as the PostgreSQL query with time zone-aware datetimes?
settings.py contains:
TIME_ZONE = 'Asia/Tehran'
USE_TZ = False
Testing in Django shell:
In [14]: from django.conf import settings
In [15]: print(settings.TIME_ZONE)
Asia/Tehran
The PostgreSQL server:
=> SHOW timezone;
TimeZone
----------
Etc/UTC
(1 row)