On my production environment only, my app uses America/Chicago
as time zone while I have TIME_ZONE = "UTC"
in my settings.
I'm running my code on Debian and the system locale is C.UTF-8
with Django 4.1.
I dug in Django code and find the source of my problem here: https://github.com/django/django/blob/c2118d72d61746f2462fca695dbf3adf44ebf8f7/django/utils/timezone.py#L72
I tried in ./manage.py shell
to reproduce the problem:
# ./manage.py shell
Python 3.10.9 (main, Dec 21 2022, 08:51:48) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> from django.utils import timezone
>>> import zoneinfo
>>> settings.TIME_ZONE
'UTC'
>>> timezone.get_current_timezone()
zoneinfo.ZoneInfo(key='America/Chicago')
And if I call the methods in get_current_timezone
, I have a different result
>>> settings.USE_DEPRECATED_PYTZ
False
>>> zoneinfo.ZoneInfo(settings.TIME_ZONE)
zoneinfo.ZoneInfo(key='UTC')
Where could the America/Chicago
come from ?
CodePudding user response:
Willem was right, I used timezone.something()
in my settings before the TIME_ZONE
was set.
For posterity: I'm using django-split-settings
and was using globs ("settings/*.py"
) and the order of the files was different locally and in production.