Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show import error for 'airflow dags list' CLI command #21991

Merged
merged 6 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions airflow/cli/commands/dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ def dag_next_execution(args):
def dag_list_dags(args):
"""Displays dags with or without stats at the command line"""
dagbag = DagBag(process_subdir(args.subdir))
if dagbag.import_errors:
from rich import print as rich_print

rich_print(
"[red][bold]Error:[/bold] Failed to load all files. "
"For details, run airflow dags list-import-errors",
ephraimbuddy marked this conversation as resolved.
Show resolved Hide resolved
file=sys.stderr,
)
AirflowConsole().print_as(
data=sorted(dagbag.dags.values(), key=lambda d: d.dag_id),
output=args.output,
Expand Down
9 changes: 9 additions & 0 deletions tests/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ def test_cli_list_dags(self):
assert "airflow/example_dags/example_complex.py" in out
assert "- dag_id:" in out

@conf_vars({('core', 'load_examples'): 'false'})
def test_cli_list_dags_prints_import_errors(self):
dag_path = os.path.join(TEST_DAGS_FOLDER, 'test_invalid_cron.py')
args = self.parser.parse_args(['dags', 'list', '--output', 'yaml', '--subdir', dag_path])
with contextlib.redirect_stderr(io.StringIO()) as temp_stdout:
dag_command.dag_list_dags(args)
out = temp_stdout.getvalue()
ephraimbuddy marked this conversation as resolved.
Show resolved Hide resolved
assert "Failed to load all files." in out

@conf_vars({('core', 'load_examples'): 'false'})
def test_cli_list_import_errors(self):
dag_path = os.path.join(TEST_DAGS_FOLDER, 'test_invalid_cron.py')
Expand Down