Skip to content

TypeError when task is manually marked success #20

@yoichiwo7

Description

@yoichiwo7

When the non-executed task is manually marked success via Web UI or CLI, the following TypeError will be raised while collecting dag duration metrics.

  File "/usr/local/lib/python3.7/site-packages/airflow_prometheus_exporter/prometheus_exporter.py", line xxx, in collect
    dag_duration_value = (dag.end_date - dag.start_date).total_seconds()
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'

Detail

The dag duration uses TaskInstance's start_date to calculate the duration.

func.min(TaskInstance.start_date).label("start_date"),

The problem is when the non-executed task is manually marked success, the corresponding TaskInstance record's start_date has no value. This will set the dag's start_date to None value and cause the TypeError mentioned in this issue.

To fix the problem, we need to add filter to dag_start_dt_query so that TaskInstance record without start_date/end_date won't be included in the query result. The filter should look like the following code.

TaskInstance.start_date.isnot(None),
TaskInstance.end_date.isnot(None),

We already applied the fix in our private environment and now it works without error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions