ashb commented on a change in pull request #4117: [AIRFLOW-3277] Correctly
observe DST transitions for cron
URL: https://github.com/apache/incubator-airflow/pull/4117#discussion_r229495682
##########
File path: tests/models.py
##########
@@ -580,6 +580,29 @@ def test_cycle(self):
with self.assertRaises(AirflowDagCycleException):
dag.test_cycle()
+ def test_following_previous_schedule(self):
+ """
+ Make sure DST transitions are properly observed
+ """
+ local_tz = pendulum.timezone('Europe/Zurich')
+ start = datetime(2018, 10, 28, 3, 00, tzinfo=local_tz)
+ utc = timezone.convert_to_utc(start)
+
+ dag = DAG('tz_dag', start_date=start, schedule_interval="'*/5 * * *
*'")
+ next = dag.following_schedule(utc)
+ next_local = local_tz.convert(next)
+
+ # should give 2018, 10, 28, 3, 5
+ self.assertEqual(next_local.hour, 3)
+ self.assertEqual(next_local.minute, 5)
+
+ prev = dag.previous_schedule(utc)
+ prev_local = local_tz.convert(prev)
+
+ # should give 2018, 10, 28, 1, 55
+ self.assertEqual(prev_local.hour, 1)
+ self.assertEqual(prev_local.minute, 55)
Review comment:
This change fixes it for hourly dags, but if (as was reported in Slack) you
have a 3am daily dag I think this breaks the TZ feature:
```
>>> start = local_tz.convert(datetime.datetime(2018, 10, 27, 3, 0))
>>> utc = timezone.convert_to_utc(start)
>>> dag = DAG('tz_dag', start_date=start, schedule_interval='0 3 * * *')
>>> next = dag.following_schedule(utc)
>>> str(next)
2018-10-27 05:00:00+02:00
```
It is no longer 3am local time as requested :( (*edit*: fix the cron
schedule field order in the example)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services