Skip to content

Commit

Permalink
Fix incorrect serialisation of the FixedTimezone (#38139)
Browse files Browse the repository at this point in the history
This issue introduced in Airflow 2.8.

When the `start_date` of a DAG is specified with a fixed timezone, its serialisation will not be correct and this causes the scheduler to crash.

(cherry picked from commit 0720ea0)
  • Loading branch information
millin authored and potiuk committed Mar 19, 2024
1 parent e0192f5 commit 5aa424d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion airflow/serialization/serialized_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def serialize(
return cls._encode(var.timestamp(), type_=DAT.DATETIME)
elif isinstance(var, datetime.timedelta):
return cls._encode(var.total_seconds(), type_=DAT.TIMEDELTA)
elif isinstance(var, Timezone):
elif isinstance(var, (Timezone, FixedTimezone)):
return cls._encode(encode_timezone(var), type_=DAT.TIMEZONE)
elif isinstance(var, relativedelta.relativedelta):
return cls._encode(encode_relativedelta(var), type_=DAT.RELATIVEDELTA)
Expand Down
13 changes: 11 additions & 2 deletions tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import multiprocessing
import os
import pickle
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone as dt_timezone
from glob import glob
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -686,7 +686,16 @@ def validate_deserialized_task(
datetime(2019, 7, 30, tzinfo=timezone.utc),
datetime(2019, 8, 1, tzinfo=timezone.utc),
),
(pendulum.datetime(2019, 8, 1, tz="UTC"), None, pendulum.datetime(2019, 8, 1, tz="UTC")),
(
datetime(2019, 8, 1, tzinfo=dt_timezone(timedelta(hours=1))),
datetime(2019, 7, 30, tzinfo=dt_timezone(timedelta(hours=1))),
datetime(2019, 8, 1, tzinfo=dt_timezone(timedelta(hours=1))),
),
(
pendulum.datetime(2019, 8, 1, tz="UTC"),
None,
pendulum.datetime(2019, 8, 1, tz="UTC"),
),
],
)
def test_deserialization_start_date(self, dag_start_date, task_start_date, expected_task_start_date):
Expand Down

0 comments on commit 5aa424d

Please sign in to comment.