You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Eason09053360 (via GitHub)" <gi...@apache.org> on 2026/09/11 11:37:22 UTC

[PR] Fix airflow teams list --output json printing prose when no teams exist [airflow]

Eason09053360 opened a new pull request, #72945:
URL: https://github.com/apache/airflow/pull/72945

   `airflow teams list --output json` (and `--output yaml`) now prints `[]` on an empty metadata DB instead of the prose line `No teams found.`, so the output can be piped into `jq` and other JSON consumers like every other `list` command.
   
   ## Why
   
   `team_list` short-circuited with a hard-coded `print("No teams found.")` when the `team` table was empty, before the result ever reached `AirflowConsole().print_as`. The `--output` flag was therefore ignored on that path: a machine-readable format emitted a prose line, and `airflow teams list --output json | jq length` failed with `parse error: Invalid numeric literal at line 1, column 3`.
   
   Every other `list` command (`pools list`, `variables list`, `connections list`, `dags list-import-errors`, ...) hands the possibly-empty sequence straight to `print_as`, which already renders the empty case per format: `[]` for json/yaml and `No data found` for table/plain. That convention is documented in `airflow-core/docs/howto/usage-cli.rst` in the `dags list-import-errors` example. `teams list` was the only list command with its own guard in front of the renderer.
   
   ## What
   
   - Drop the empty-list guard in `team_list` so the empty sequence flows through `print_as` like the sibling commands.
   - Remove `NO_TEAMS_LIST_MSG`, which had no other reader.
   - Replace the single-format `test_team_list_empty` with a parametrized case that pins the empty output for all four formats.
   
   Output on an empty database, before vs. after:
   
   | format | before | after |
   |---|---|---|
   | json | `No teams found.` | `[]` |
   | yaml | `No teams found.` | `[]` |
   | table (default) | `No teams found.` | `No data found` |
   | plain | `No teams found.` | `No data found` |
   
   **Note for reviewers on the table/plain rows.** The json/yaml rows are the bug. The table/plain rows are a side effect of removing the guard: the human-readable wording moves from `No teams found.` (shipped in 3.2.0) to the `No data found` that `print_as` and every other list command already emit. A script that greps stdout for the old wording would stop matching. I kept the plain removal because it makes `teams list` consistent with the documented convention and deletes code rather than adding a format-specific branch. If you would rather keep the old wording for the human formats, the alternative is to guard only when `args.output` is `table` or `plain` and let json/yaml through. Happy to switch, and to add a newsfragment if you consider the wording change user-facing.
   
   **Same defect elsewhere, deliberately not in this PR.** `airflow plugins --output json` has the identical shape: `dump_plugins` prints `No plugins loaded` and returns before `print_as`, and `test_plugins_command.py` pins that prose while invoking `--output=json`. Left for a follow-up so this diff stays one command.
   
   ## How to test
   
   Run the changed test file:
   
       uv run --project airflow-core pytest airflow-core/tests/unit/cli/commands/test_team_command.py -q
   
   With the fix, all 40 tests in the file pass. Reverting the change in `team_command.py` and re-running the whole file makes the four `test_team_list_empty` cases fail.
   
   Manual check on an empty metadata DB (each line was run, output shown after `#`):
   
   - `airflow teams list --output json | jq length` # `0`
   - `airflow teams list --output yaml` # `[]`
   - `airflow teams list` # `No data found`
   - `airflow teams create team-a && airflow teams list --output json | jq .` # `[{"name": "team-a"}]`
   
   Static checks: `prek run --files` on the two changed files and the `mypy-airflow-core` hook both pass.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Fable 5.1)
   
   Generated-by: Claude Code (Fable 5.1) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix airflow teams list --output json printing prose when no teams exist [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #72945:
URL: https://github.com/apache/airflow/pull/72945


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix airflow teams list --output json printing prose when no teams exist [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #72945:
URL: https://github.com/apache/airflow/pull/72945#issuecomment-5635614079

   Nice catch!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org