From 8c2d3dca633629effad17ccc98730234f740d03f Mon Sep 17 00:00:00 2001 From: jodizzle Date: Thu, 4 Jun 2026 07:54:50 -0400 Subject: 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. --- AUTHORS | 1 + django/conf/__init__.py | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 36914d2950..1385cc5afd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -533,6 +533,7 @@ answer newbie questions, and generally made Django that much better: Joachim Jablon Joao Oliveira Joao Pedro Silva + jodizzle Joe Heck Joe Jackson Joel Bohman 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). -- cgit v1.3