You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "BobSong-dev (via GitHub)" <gi...@apache.org> on 2026/08/18 10:23:29 UTC
[PR] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
BobSong-dev opened a new pull request, #71763:
URL: https://github.com/apache/airflow/pull/71763
Summary
Add the `airflowctl tasks logs` command to fetch a task instance's logs for a given try through the existing REST endpoint.
Changes
- Add `TaskInstancesOperations.logs()` calling `GET /api/v2/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/logs/{try_number}`.
- Register the `tasks logs` command: `airflowctl tasks logs DAG_ID DAG_RUN_ID TASK_ID [--map-index N] [--try-number N]`; `--try-number` defaults to the latest attempt, matching the webserver UI.
- Keep required parameters positional per the airflowctl parameter style consensus (#66768); the issue's suggested `--dag-id`/`--dag-run-id`/`--task-id` flag form was dropped to comply with that convention.
- Limit scope to the primary logs endpoint; `externalLogUrl` handling is left for a follow-up.
Testing
Added unit tests covering the command: default latest attempt, explicit try number and map index, structured and plain-text log output, 404 handling, and non-404 error propagation. All 35 tests in `test_task_command.py` pass. Added `tasks logs` lines to the integration test command list. `ruff format` and `ruff check` pass on all changed files.
closes: #69947
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — DeepSeek V4 Pro
Generated-by: DeepSeek V4 Pro following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions),I also conducted local testing, and no issues were found.
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "BobSong-dev (via GitHub)" <gi...@apache.org>.
BobSong-dev closed pull request #71763: Add airflowctl tasks logs command for retrieving task instance logs
URL: https://github.com/apache/airflow/pull/71763
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "1fanwang (via GitHub)" <gi...@apache.org>.
1fanwang commented on PR #71763:
URL: https://github.com/apache/airflow/pull/71763#issuecomment-5881029765
Confirmed the blocker against a real cluster rather than a stand-in, since my first pass used a local copy of the route signature.
```
$ curl -s -o /dev/null -w '%{http_code}\n' .../taskInstances/t/logs/1?map_index=-1
404
$ curl -s ... /taskInstances/t/logs/-1?map_index=-1
422 {"detail":[{"type":"greater_than_equal","loc":["path","try_number"],
"msg":"Input should be greater than or equal to 0","input":"-1","ctx":{"ge":0}}]}
```
The `404` on the first call is the useful half: the path and auth are correct and the handler ran, so the `422` is the endpoint rejecting `try_number` itself rather than a routing miss. The suggestion on `ARG_TRY_NUMBER` applies unchanged.
One retraction: I asked for a newsfragment, and that was wrong. There is no `newsfragments` directory under `airflow-ctl/`, so this does not take one. Sorry for the detour.
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "1fanwang (via GitHub)" <gi...@apache.org>.
1fanwang commented on code in PR #71763:
URL: https://github.com/apache/airflow/pull/71763#discussion_r4127679648
##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -346,6 +346,20 @@ def _load_help_texts_yaml() -> dict[str, dict[str, str]]:
help="Mapped task index",
)
+# Task logs command args. Required primitive parameters stay positional per the
+# airflowctl parameter style consensus (#66768).
+ARG_TASKS_LOGS_DAG_RUN_ID = Arg(
+ flags=("dag_run_id",),
+ type=str,
+ help="The run ID of the Dag run",
+)
+ARG_TRY_NUMBER = Arg(
+ flags=("--try-number",),
+ type=int,
+ default=-1,
+ help="The try number of the task instance logs to fetch; -1 fetches the latest attempt",
+)
Review Comment:
```suggestion
ARG_TRY_NUMBER = Arg(
flags=("--try-number",),
type=int,
required=True,
help="The try number of the task instance logs to fetch",
)
```
`/logs/{try_number}` types that path param as `NonNegativeInt` and filters `TaskInstance.try_number == try_number`, so `-1` is rejected by validation before the handler runs. Against a real cluster:
```
$ curl -s -w '\nHTTP=%{http_code}\n' -H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
"$URL/api/v2/dags/nonexistent_dag_x/dagRuns/nonexistent_run_x/taskInstances/nonexistent_ti_x/logs/1?map_index=-1"
{"detail":"TaskInstance not found"}
HTTP=404
$ ... /logs/-1?map_index=-1
{"detail":[{"type":"greater_than_equal","loc":["path","try_number"],"msg":"Input
should be greater than or equal to 0","input":"-1","ctx":{"ge":0}}]}
HTTP=422
```
The `404` on the first call is the useful half: it shows the path and auth are right and the handler ran, so the `422` is the endpoint rejecting `try_number` itself, not a routing miss.
`required=True` matches the endpoint, and the `externalLogUrl` sibling route is stricter still (`PositiveInt`), so there is no server-side "latest" to fall back on. Keeping the default is still workable if you resolve it client-side off `taskinstances get`, at the cost of one extra call.
Two spots to update alongside it: `test_logs_defaults_to_latest_attempt` and the `test_airflowctl_commands.py:104` line both rely on the default, so they will need an explicit `--try-number`.
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "1fanwang (via GitHub)" <gi...@apache.org>.
1fanwang commented on code in PR #71763:
URL: https://github.com/apache/airflow/pull/71763#discussion_r4129610297
##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -346,6 +346,20 @@ def _load_help_texts_yaml() -> dict[str, dict[str, str]]:
help="Mapped task index",
)
+# Task logs command args. Required primitive parameters stay positional per the
+# airflowctl parameter style consensus (#66768).
+ARG_TASKS_LOGS_DAG_RUN_ID = Arg(
+ flags=("dag_run_id",),
+ type=str,
+ help="The run ID of the Dag run",
+)
+ARG_TRY_NUMBER = Arg(
+ flags=("--try-number",),
+ type=int,
+ default=-1,
+ help="The try number of the task instance logs to fetch; -1 fetches the latest attempt",
+)
Review Comment:
I see this fixed in 55a23dfbd2 — required=True, integration test passes --try-number explicitly.
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #71763:
URL: https://github.com/apache/airflow/pull/71763#issuecomment-5326862070
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our [Contributors' Guide](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
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] Add airflowctl tasks logs command for retrieving task instance logs [airflow]
Posted by "1fanwang (via GitHub)" <gi...@apache.org>.
1fanwang commented on code in PR #71763:
URL: https://github.com/apache/airflow/pull/71763#discussion_r4127679648
##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -346,6 +346,20 @@ def _load_help_texts_yaml() -> dict[str, dict[str, str]]:
help="Mapped task index",
)
+# Task logs command args. Required primitive parameters stay positional per the
+# airflowctl parameter style consensus (#66768).
+ARG_TASKS_LOGS_DAG_RUN_ID = Arg(
+ flags=("dag_run_id",),
+ type=str,
+ help="The run ID of the Dag run",
+)
+ARG_TRY_NUMBER = Arg(
+ flags=("--try-number",),
+ type=int,
+ default=-1,
+ help="The try number of the task instance logs to fetch; -1 fetches the latest attempt",
+)
Review Comment:
```suggestion
ARG_TRY_NUMBER = Arg(
flags=("--try-number",),
type=int,
required=True,
help="The try number of the task instance logs to fetch",
)
```
`/logs/{try_number}` types that path param as `NonNegativeInt` and filters `TaskInstance.try_number == try_number`, so `-1` is rejected by validation before the handler runs. The default path 422s:
```
$ airflowctl tasks logs dags.example_bash_operator manual__2026-01-01 runme_0
Client error message: {'detail': [{'type': 'greater_than_equal', 'loc': ['path',
'try_number'], 'msg': 'Input should be greater than or equal to 0', 'input': '-1',
'ctx': {'ge': 0}}]}
Client error, Please check the command and its parameters. If you need help, run
the command with --help.
exit=1
$ airflowctl tasks logs dags.example_bash_operator manual__2026-01-01 runme_0 --try-number 1
INFO - first line
INFO - second line
exit=0
```
`required=True` matches the endpoint, and the `externalLogUrl` sibling route is stricter still (`PositiveInt`), so there is no server-side "latest" to fall back on. Keeping the default is still workable if you resolve it client-side off `taskinstances get`, at the cost of one extra call.
Two spots to update alongside it: `test_logs_defaults_to_latest_attempt` and the `test_airflowctl_commands.py:104` line both rely on the default, so they will need an explicit `--try-number`.
--
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