Hi,
I found an issue with the "Number of runs:" pulldown menu. Looks like we
intend to retrieve task instances for the last X runs until the "Base".
However, the logic has a flaw IMO.

It is currently implemented as below (see copy snippet at the end). It
tries to calculate execution_date of the last 'num_runs' based on DAG's
interval. This will work if the schedule interval does not change, or if
there are not manual/external triggered runs. An extreme example is a DAG
with no schedules and purely depend on CLI to start the run. This will also
not work if a DAG is triggered by another DAG because there is no fixed
schedule interval between runs.

IMO, the correct way is to query the database for TIs which have
execution_date earlier than "base" with maximum number of query entries be
'num_runs', or just implement

dates = dag.date_range(base_date, num=-abs(num_runs))
min_date = dates[0] if dates else datetime(2000, 1, 1)
for ti in task.get_task_instances(session, start_date=min_date,
 end_date=base_date)

Thanks!


    def date_range(self, start_date, num=None, end_date=datetime.now()):
        if num:
            end_date = None
        return utils_date_range(
            start_date=start_date, end_date=end_date,
            num=num, delta=self._schedule_interval)

Reply via email to