Kshitij Bhadage
Kshitij Bhadage

Reputation: 430

Unable to deploy a DAG in Airflow

I am unable to deploy a DAG in airflow. Constantly giving the same error. Running on 8080 port and scheduler is also on.

Running %s on host %s <TaskInstance: bworkflow_dag.bworkflow_template 2020-08-11T00:00:00+00:00 [failed]> airflow-instance-test.c.cc-data-sandbox.internal
[2020-08-11 14:46:29,030] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-08-11 14:46:29,031] {dagbag.py:396} INFO - Filling up the DagBag from /home/kshitij/airflow/dags
/home/kshitij/.local/lib/python3.5/site-packages/airflow/models/dag.py:1342: PendingDeprecationWarning: The requested task could not be added to the DAG because a task with task_id create_tag_template_field_result is already in the DAG. Starting in Airflow 2.0, trying to overwrite a task will raise an exception.
  category=PendingDeprecationWarning)
Running %s on host %s <TaskInstance: bworkflow_dag.bworkflow_template 2020-08-11T00:00:00+00:00 [failed]> airflow-instance-test.c.cc-data-sandbox.internal

I am using the correct path i.e. ~/airflow/dags

Find the snippet of the code:

from builtins import range
from datetime import timedelta
from airflow.models import DAG
from airflow.utils.dates import days_ago
from airflow.contrib.operators.dataproc_operator import DataprocWorkflowTemplateInstantiateOperator

args = {
    'owner': 'Airflow',
    'start_date': days_ago(2),
}

dag = DAG(
    dag_id='workflow_dag',
    default_args=args,
    schedule_interval=None,
    dagrun_timeout=timedelta(days=1),
)

workflow_template = DataprocWorkflowTemplateInstantiateOperator(
    template_id="workflow_rds",
    project_id="<project name>",
    task_id="workflow_template",
    dag=dag)


workflow_template


if __name__ == "__main__":
    dag.cli()

It's a single task DAG.

Let me know where I am going wrong.

Upvotes: 3

Views: 2139

Answers (1)

y2k-shubham
y2k-shubham

Reputation: 11607

As discussed over comments, following lines were not required and needed to be removed

...
workflow_template


if __name__ == "__main__":
    dag.cli()

taking them one-by-one

  • workflow_template: this does nothing; just referencing a variable that holds a task (removing it is merely cleanup)
  • if __name__ == "__main__":: intended to execute some piece of code only when file is executed as a main program. Not needed in a DAG file
  • dag.cli(): this i believe was the cuprit. i haven't used this method before but the docstring says it Exposes a CLI specific to this DAG, something that was creating problems for the process parsing dag-definition file (webserver actually)

Upvotes: 3

Related Questions