Reputation: 8273
I am trying to create dynamic dag but seems to be failing at the minute. I came across creating the DAG object in two different:
from airflow.models import DAG
https://airflow.apache.org/concepts.html#latest-run-onlyfrom airflow import DAG
https://airflow.apache.org/tutorial.html
This really confused me because within the same documentation there are two ways of instantiating DAG object.Upvotes: 0
Views: 391
Reputation: 3257
Both are importing the same DAG class. Just an attribute of how python imports works.
When you do from airflow.models import DAG
python is importing the models file and assigning the variable DAG to the DAG class defined in the models file.
When you do from airflow import DAG
python is importing the variable DAG defined in init.py, which is in fact just from airflow.models import DAG
.
A minimal version being:
class DAG():
pass
from airflow.models import DAG
# import __init__.py which imports models.py which contains DAG
from airflow import DAG
# or this which just imports models.py which contains DAG
from airflow.models import DAG
All that being said, if your dynamic DAG is failing, I doubt it's related to this import
Upvotes: 5