Skip to content

Commit

Permalink
Add support for timezone as string in cron interval timetable (#23279)
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe authored May 4, 2022
1 parent dfe0f75 commit fdf1a53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion airflow/timetables/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ class CronDataIntervalTimetable(_DataIntervalTimetable):
Don't pass ``@once`` in here; use ``OnceTimetable`` instead.
"""

def __init__(self, cron: str, timezone: Timezone) -> None:
def __init__(self, cron: str, timezone: Union[str, Timezone]) -> None:
self._expression = cron_presets.get(cron, cron)

if isinstance(timezone, str):
timezone = Timezone(timezone)
self._timezone = timezone

descriptor = ExpressionDescriptor(
Expand Down
5 changes: 5 additions & 0 deletions tests/timetables/test_interval_timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,8 @@ def test_validate_failure(timetable: Timetable, error_message: str) -> None:
with pytest.raises(AirflowTimetableInvalid) as ctx:
timetable.validate()
assert str(ctx.value) == error_message


def test_cron_interval_timezone_from_string():
timetable = CronDataIntervalTimetable("@hourly", "UTC")
assert timetable.serialize()['timezone'] == 'UTC'

0 comments on commit fdf1a53

Please sign in to comment.