Skip to content

Commit

Permalink
zoneinfo.ZoneInfo is not available on < Python 3.9 (#34804)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolkedebruin authored Oct 6, 2023
1 parent c01abd1 commit 25cd12d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions airflow/serialization/serializers/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import datetime
import sys
from typing import TYPE_CHECKING, Any, cast

from airflow.utils.module_loading import qualname
Expand All @@ -29,10 +30,15 @@
serializers = [
"pendulum.tz.timezone.FixedTimezone",
"pendulum.tz.timezone.Timezone",
"zoneinfo.ZoneInfo",
"backports.zoneinfo.ZoneInfo",
]

PY39 = sys.version_info >= (3, 9)

if PY39:
serializers.append("zoneinfo.ZoneInfo")
else:
serializers.append("backports.zoneinfo.ZoneInfo")

deserializers = serializers

__version__ = 1
Expand Down Expand Up @@ -79,17 +85,11 @@ def deserialize(classname: str, version: int, data: object) -> Any:
if isinstance(data, int):
return fixed_timezone(data)

if classname == "zoneinfo.ZoneInfo":
from zoneinfo import ZoneInfo

return ZoneInfo(data)

if classname == "backports.zoneinfo.ZoneInfo":
# python version might have been upgraded, so we need to check
if "zoneinfo.ZoneInfo" in classname:
try:
from backports.zoneinfo import ZoneInfo
except ImportError:
from zoneinfo import ZoneInfo
except ImportError:
from backports.zoneinfo import ZoneInfo

return ZoneInfo(data)

Expand Down

0 comments on commit 25cd12d

Please sign in to comment.