diff options
| author | jodizzle <github.35h77@passmail.com> | 2026-06-04 07:54:50 -0400 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-06-04 15:12:13 -0400 |
| commit | 8c2d3dca633629effad17ccc98730234f740d03f (patch) | |
| tree | 08a23b57136a297ce38dda62adb0644fa2fb5cca | |
| parent | 4bbc27c8686f10f9556cef02dbfa9f5157fbcf56 (diff) | |
Fixed #37110 -- Fixed time zone validation when missing zone directory.
On Unix systems that lack time zone information stored at
`/usr/share/zoneinfo`, time zones couldn't be validated.
Python's `zoneinfo` module was introduced in Python 3.9, meaning all
modern Django versions should support it's use.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/conf/__init__.py | 10 |
2 files changed, 5 insertions, 6 deletions
@@ -533,6 +533,7 @@ answer newbie questions, and generally made Django that much better: Joachim Jablon <ewjoachim@gmail.com> Joao Oliveira <joaoxsouls@gmail.com> Joao Pedro Silva <j.pedro004@gmail.com> + jodizzle Joe Heck <http://www.rhonabwy.com/wp/> Joe Jackson <joe@joejackson.me> Joel Bohman <mail@jbohman.com> diff --git a/django/conf/__init__.py b/django/conf/__init__.py index d462f82acf..020047ffd8 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -10,7 +10,7 @@ import importlib import os import time import warnings -from pathlib import Path +import zoneinfo from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured @@ -295,11 +295,9 @@ class Settings: ) if hasattr(time, "tzset") and self.TIME_ZONE: - # When we can, attempt to validate the timezone. If we can't find - # this file, no check happens and it's harmless. - zoneinfo_root = Path("/usr/share/zoneinfo") - zone_info_file = zoneinfo_root.joinpath(*self.TIME_ZONE.split("/")) - if zoneinfo_root.exists() and not zone_info_file.exists(): + try: + zoneinfo.ZoneInfo(self.TIME_ZONE) + except zoneinfo.ZoneInfoNotFoundError: raise ValueError("Incorrect timezone setting: %s" % self.TIME_ZONE) # Move the time zone info into os.environ. See ticket #2315 for why # we don't do this unconditionally (breaks Windows). |
