Skip to content

Commit 4788f5d

Browse files
authored
CLI: Exclude example dags when a bundle is passed (#50401)
1 parent 38fa6f4 commit 4788f5d

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
@@ -833,6 +833,20 @@ def test_dag_test_with_mark_success(self, mock__execute_task):
833833
assert len(mock__execute_task.call_args_list) == 1
834834
assert mock__execute_task.call_args_list[0].kwargs["ti"].task_id == "dummy_operator"
835835

836+
@conf_vars({("core", "load_examples"): "false"})
837+
def test_get_dag_excludes_examples_with_bundle(self, configure_testing_dag_bundle):
838+
"""Test that example DAGs are excluded when bundle names are passed."""
839+
from airflow.utils.cli import get_dag
840+
841+
with configure_testing_dag_bundle(TEST_DAGS_FOLDER / "test_sensor.py"):
842+
# example DAG should not be found since include_examples=False
843+
with pytest.raises(AirflowException, match="could not be found"):
844+
get_dag(bundle_names=["testing"], dag_id="example_simplest_dag")
845+
846+
# However, "test_sensor.py" should exist
847+
dag = get_dag(bundle_names=["testing"], dag_id="test_sensor")
848+
assert dag.dag_id == "test_sensor"
849+
836850

837851
class TestCliDagsReserialize:
838852
parser = cli_parser.get_parser()

0 commit comments

Comments
 (0)