Skip to content

Commit 5bfd242

Browse files
committed
CLI: Exclude example dags when a bundle is passed (#50401)
(cherry picked from commit 4788f5d)
1 parent 3128741 commit 5bfd242

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

airflow-core/src/airflow/utils/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def get_dag(bundle_names: list | None, dag_id: str, from_db: bool = False) -> DA
277277
manager = DagBundlesManager()
278278
for bundle_name in bundle_names:
279279
bundle = manager.get_bundle(bundle_name)
280-
dagbag = DagBag(dag_folder=bundle.path, bundle_path=bundle.path)
280+
dagbag = DagBag(dag_folder=bundle.path, bundle_path=bundle.path, include_examples=False)
281281
dag = dagbag.dags.get(dag_id)
282282
if dag:
283283
break

airflow-core/tests/unit/cli/commands/test_dag_command.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,20 @@ def test_dag_test_with_mark_success(self, mock__execute_task):
777777
assert len(mock__execute_task.call_args_list) == 1
778778
assert mock__execute_task.call_args_list[0].kwargs["ti"].task_id == "dummy_operator"
779779

780+
@conf_vars({("core", "load_examples"): "false"})
781+
def test_get_dag_excludes_examples_with_bundle(self, configure_testing_dag_bundle):
782+
"""Test that example DAGs are excluded when bundle names are passed."""
783+
from airflow.utils.cli import get_dag
784+
785+
with configure_testing_dag_bundle(TEST_DAGS_FOLDER / "test_sensor.py"):
786+
# example DAG should not be found since include_examples=False
787+
with pytest.raises(AirflowException, match="could not be found"):
788+
get_dag(bundle_names=["testing"], dag_id="example_simplest_dag")
789+
790+
# However, "test_sensor.py" should exist
791+
dag = get_dag(bundle_names=["testing"], dag_id="test_sensor")
792+
assert dag.dag_id == "test_sensor"
793+
780794

781795
class TestCliDagsReserialize:
782796
parser = cli_parser.get_parser()

0 commit comments

Comments
 (0)