This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch v2-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 97d98bbbe391095cb2534cdd1377395e751b1810
Author: Rik Heijdens <[email protected]>
AuthorDate: Thu Feb 25 15:40:38 2021 +0100

    Gracefully handle missing start_date and end_date for DagRun (#14452)
    
    closes: #14384
    
    This PR fixes two issues:
    
    1) A TypeError that would be raised from 
_emit_duration_stats_for_finished_state() when the scheduler transitions a 
DagRun from a running state into a success or failed state if the DagRun did 
not have a start_date or end_date set.
    
    2) An issue with the DagRunEditForm, which would clear the start_date and 
end_date for a DagRun, if the form was used to transition a DagRun from a 
failed state back into a running state (or any other state). In the event where 
the scheduler would determine the DagRun should've been in the failed or 
success state (e.g. because the task instances weren't cleared), then this 
would lead to a scheduler crash.
    
    (cherry picked from commit 997a009715fb82c241a47405cc8647d23580af25)
---
 airflow/models/dagrun.py | 6 ++++++
 airflow/www/views.py     | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/airflow/models/dagrun.py b/airflow/models/dagrun.py
index fe7b29c..fae58e1 100644
--- a/airflow/models/dagrun.py
+++ b/airflow/models/dagrun.py
@@ -611,6 +611,12 @@ class DagRun(Base, LoggingMixin):
     def _emit_duration_stats_for_finished_state(self):
         if self.state == State.RUNNING:
             return
+        if self.start_date is None:
+            self.log.warning('Failed to record duration of %s: start_date is 
not set.', self)
+            return
+        if self.end_date is None:
+            self.log.warning('Failed to record duration of %s: end_date is not 
set.', self)
+            return
 
         duration = self.end_date - self.start_date
         if self.state is State.SUCCESS:
diff --git a/airflow/www/views.py b/airflow/www/views.py
index c1155ee..78dbbea 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -3290,7 +3290,7 @@ class DagRunModelView(AirflowModelView):
         'external_trigger',
         'conf',
     ]
-    edit_columns = ['state', 'dag_id', 'execution_date', 'run_id', 'conf']
+    edit_columns = ['state', 'dag_id', 'execution_date', 'start_date', 
'end_date', 'run_id', 'conf']
 
     base_order = ('execution_date', 'desc')
 

Reply via email to