amoghrajesh opened a new pull request, #77009:
URL: https://github.com/apache/airflow/pull/77009
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull
request.
Write a good git commit message following this guide:
https://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the
documentation.
For user-facing UI changes, please attach before/after screenshots (or a
short
screen recording) so reviewers can assess the visual impact.
Feel free to ping (in general) for the review if you do not see reaction for
a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we
sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR,
please
change below checkbox to `[X]` followed by the name of the tool, uncomment
the "Generated-by".
-->
- [x] Yes (please specify the tool below)
<!--
Generated-by: [Tool Name] following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
### Motivation
#76833 adds a banner on the task logs page that shows what durable execution
did on a retry. To know whether a task is durable, the banner fetches the
`__airflow_durable__` task state store key for every task instance it shows,
and most of those fetches return 404. I was wondering whether there is a better
way to tell if a task is durable. Today nothing in the serialized task or the
task API says so.
### What
Store an `is_durable` flag on each serialized task and return it from the
public task API, so the UI can check it before fetching anything.
### Proposed change
- The serializer writes `"_is_durable": true` when durable execution is on
for the task, and writes nothing otherwise, the same way `_is_empty` and
`_can_skip_downstream` work. Deserialized tasks get an `is_durable` property
that defaults to `False`, so Dags serialized before this change read as not
durable.
- `TaskResponse` gains `is_durable: bool`. The openapi spec, the UI client
and the `airflow-ctl` datamodels are regenerated.
- A task counts as durable when its `durable` setting is `True`. This covers
`ResumableJobMixin` operators and `KubernetesPodOperator`, which does durable
execution without the mixin.
### Changes of Note
- Mapped tasks need their own branch. At parse time a mapped task is a
`MappedOperator` placeholder with no `durable` attribute. `partial()` only
copies `BaseOperator` arguments from the Dag's `default_args` into
`partial_kwargs`, and `durable` is a mixin argument. So for mapped tasks the
check reads, in order:
1. `durable` passed to `.partial()`
2. `durable` in the Dag or task group `default_args`, merged with
`get_merged_defaults`, the same function `partial()` uses
3. the class default: `True` for `ResumableJobMixin` operators
Without step 2, `default_args={"durable": False}` would serialize a mapped
task as durable even though it runs with `durable=False`.
- `_is_durable` is not added to `schema.json`, matching `_is_empty` and
`_can_skip_downstream`. The operator schema does not enforce these flags.
- `scripts/ci/prek/ts_compile_lint_ui.py`: pass
`--no-error-on-unmatched-pattern` to oxlint. Since #76491 the hook fails
whenever the only TS files changed are generated `openapi-gen/` files, because
oxlint ignores them and exits 1 on an empty file list. The oxfmt call next to
it already uses the same flag.
### User implications / backcompat
- The task API response gains a new field, `is_durable`. Nothing is removed.
- After upgrading, each Dag with a durable task gets one new serialized Dag
version on its next parse, because its tasks gain the `_is_durable` key. Dags
without durable tasks don't change.
- `_is_durable` is added to the public task fields in `dag_version_diff.py`
(diff schema v1), so it appears in Dag version diffs.
### Testing
Unit tests cover plain and mapped mixin tasks with `durable` unset,
`durable=False`, and mapped `default_args={"durable": False}`, plus a non-mixin
operator with and without `durable=True`. The tasks API and airflow-ctl tests
expect the new field.
End-to-end in Breeze, with a Dag that has a `BashOperator`,
`DatabricksRunNowOperator` (default, `durable=False`, and mapped) and
`KubernetesPodOperator` (default and `durable=True`):
**Serialized task JSON from the DB:**
```json
{"task_id": "plain_bash", "task_type": "BashOperator"}
{"task_id": "dbx_durable", "task_type": "DatabricksRunNowOperator",
"_is_durable": true}
{"task_id": "dbx_not_durable", "task_type": "DatabricksRunNowOperator"}
{"task_id": "dbx_mapped_durable", "task_type": "DatabricksRunNowOperator",
"_is_durable": true, "_is_mapped": true}
{"task_id": "kpo_durable", "task_type": "KubernetesPodOperator",
"_is_durable": true}
{"task_id": "kpo_default", "task_type": "KubernetesPodOperator",
"_is_durable": true}
```
**`GET /api/v2/dags/{dag_id}/tasks/{task_id}` responses:**
```json
{"task_id": "plain_bash", "operator_name": "BashOperator", "is_mapped":
false, "is_durable": false}
{"task_id": "dbx_durable", "operator_name": "DatabricksRunNowOperator",
"is_mapped": false, "is_durable": true}
{"task_id": "dbx_not_durable", "operator_name": "DatabricksRunNowOperator",
"is_mapped": false, "is_durable": false}
{"task_id": "dbx_mapped_durable", "operator_name":
"DatabricksRunNowOperator", "is_mapped": true, "is_durable": true}
{"task_id": "kpo_durable", "operator_name": "KubernetesPodOperator",
"is_mapped": false, "is_durable": true}
{"task_id": "kpo_default", "operator_name": "KubernetesPodOperator",
"is_mapped": false, "is_durable": true}
```
**Mapped tasks: flag at parse time vs. `durable` on the unmapped operator at
run time:**
| Mapped task | `partial_kwargs["durable"]` | Serialized `is_durable` |
`durable` at run time (unmapped) |
|---|---|---|---|
| `.partial(task_id="plain")` | absent | True | True |
| Dag `default_args={"durable": False}` | absent | False | False |
| `.partial(task_id="via_partial", durable=False)` | False | False | False |
### What's next
- Once #76833 merges, the logs banner checks `is_durable` before fetching
the task state store.
- A mapped `KubernetesPodOperator` that doesn't pass `durable` reports
`false`. KPO sets its default inside `__init__`, which hasn't run at parse
time. Fixing it needs a class-level default on KPO.
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]