Skip to content

Commit

Permalink
Check name of SubDag class instead of class itself
Browse files Browse the repository at this point in the history
`airflow.operators.SubDagOperator` and
`airflow.operators.subdag_operator.SubDagOperator` are NOT the
same. Airflow needs to check against both classes to determine
if a task is in fact a SubDagOperator. This is because of Airflow's
import machinery. It is *probably* ok to check both classes with
`isinstance()` but the behavior is surprising and to cover our bases
we check for __class__.__name__ and a `subdag` attr.

closes #1168
  • Loading branch information
jlowin committed Mar 27, 2016
1 parent aaafff6 commit 7398dda
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,11 +2255,13 @@ def subdags(self):
"""
Returns a list of the subdag objects associated to this DAG
"""
# Late import to prevent circular imports
from airflow.operators import SubDagOperator
# Check SubDag for class but don't check class directly, see
# https://github.com/airbnb/airflow/issues/1168
l = []
for task in self.tasks:
if isinstance(task, SubDagOperator):
if (
task.__class__.__name__ == 'SubDagOperator' and
hasattr(task, 'subdag')):
l.append(task.subdag)
l += task.subdag.subdags
return l
Expand Down

0 comments on commit 7398dda

Please sign in to comment.