Skip to content

Commit

Permalink
Fix import cycle in cluster policy examples (apache#14973)
Browse files Browse the repository at this point in the history
If you import anything directly from `airflow` in cluster policy file, an import cycle will prevent the policy from getting loaded.

This PR fixes the import in the example and adds a small note warning about this.

closes: apache#14945
  • Loading branch information
dstandish authored Mar 24, 2021
1 parent f6a1774 commit eb91bdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/apache-airflow/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,12 @@ Here is what it may look like:
:start-after: [START example_dag_cluster_policy]
:end-before: [END example_dag_cluster_policy]


.. note::

To avoid import cycles, if using ``DAG`` in type annotations in your cluster policy, be sure to import from ``airflow.models`` and not from ``airflow``.


Task level cluster policy
-----------------------------
For example, this function could apply a specific queue property when
Expand Down
3 changes: 1 addition & 2 deletions tests/cluster_policies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
from datetime import timedelta
from typing import Callable, List

from airflow import DAG
from airflow.configuration import conf
from airflow.exceptions import AirflowClusterPolicyViolation
from airflow.models import TaskInstance
from airflow.models import DAG, TaskInstance
from airflow.models.baseoperator import BaseOperator


Expand Down

0 comments on commit eb91bdc

Please sign in to comment.