You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Lee-W (via GitHub)" <gi...@apache.org> on 2025/10/29 09:07:33 UTC
[PR] fix(task_instance): Ignore NotFullyPopulated if TriggerRule is not se… [airflow]
Lee-W opened a new pull request, #57474:
URL: https://github.com/apache/airflow/pull/57474
…t to ALL_SUCCESS
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! 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.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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(task_instance): Ignore NotFullyPopulated if TriggerRule is not se… [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2472355880
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -286,30 +290,53 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
Review Comment:
I would like to make it explicit so that if we add other rules we don't accidentally include it here. But yep, they are the same
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485422347
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
Same. Not sure what TriggerRule we're to add in the future. Not success might accidentally include new one which might not make sense to include here
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #57474:
URL: https://github.com/apache/airflow/pull/57474#issuecomment-3484084311
### Backport failed to create: v3-1-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/19059732530'> Run details </a>
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>❌</td>
<td>v3-1-test</td>
<td><a href="https://github.com/apache/airflow/commit/e05849de0b452a3c92efee3e389c2bed1cd4fc95"><img src='https://img.shields.io/badge/Commit-e05849d-red' alt='Commit Link'></a></td>
</tr>
</table>
You can attempt to backport this manually by running:
```bash
cherry_picker e05849d v3-1-test
```
This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
```bash
cherry_picker --continue
```
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485425339
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
Oh good call, but I think its more explicit to have this as explictly not success. Or if we are worried about future trigger rules, define a type for this?
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485419751
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
Same as not success?
##########
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py:
##########
@@ -436,6 +443,71 @@ def task_3():
)
assert response.json()["upstream_map_indexes"] == {"tg.task_2": [0, 1, 2, 3, 4, 5]}
+ def test_dynamic_task_mapping_with_trigger_rule(
+ self, client: Client, dag_maker: DagMaker, session: Session
+ ):
+ """
+ Test that the Task Instance upstream_map_indexes is not populuated but
+ the downstream task should still be run due to trigger rule.
+ """
+
+ with dag_maker(session=session, serialized=True):
+
+ @task
+ def task_1():
+ raise AirflowSkipException()
+
+ @task_group
+ def tg(x):
+ @task
+ def task_2():
+ raise AirflowSkipException()
+
+ task_2()
+
+ @task(trigger_rule=TriggerRule.ALL_DONE)
+ def task_3():
+ pass
+
+ @task
+ def task_4():
+ pass
+
+ tg.expand(x=task_1()) >> [task_3(), task_4()]
+
+ dr = dag_maker.create_dagrun()
+
+ decision = dr.task_instance_scheduling_decisions(session=session)
+
+ # Simulate task_1 skipped
+ (ti_1,) = decision.schedulable_tis
+ ti_1.state = TaskInstanceState.SKIPPED
+ session.flush()
+
+ # Now task_2 in mapped tagk group is not expanded and also skipped..
Review Comment:
```suggestion
# Now task_2 in mapped task group is not expanded and also skipped..
```
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485651038
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -286,30 +290,53 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
Review Comment:
updated
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
updated
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485653001
##########
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py:
##########
@@ -436,6 +443,71 @@ def task_3():
)
assert response.json()["upstream_map_indexes"] == {"tg.task_2": [0, 1, 2, 3, 4, 5]}
+ def test_dynamic_task_mapping_with_trigger_rule(
+ self, client: Client, dag_maker: DagMaker, session: Session
+ ):
+ """
+ Test that the Task Instance upstream_map_indexes is not populuated but
+ the downstream task should still be run due to trigger rule.
+ """
+
+ with dag_maker(session=session, serialized=True):
+
+ @task
+ def task_1():
+ raise AirflowSkipException()
+
+ @task_group
+ def tg(x):
+ @task
+ def task_2():
+ raise AirflowSkipException()
+
+ task_2()
+
+ @task(trigger_rule=TriggerRule.ALL_DONE)
+ def task_3():
+ pass
+
+ @task
+ def task_4():
+ pass
+
+ tg.expand(x=task_1()) >> [task_3(), task_4()]
+
+ dr = dag_maker.create_dagrun()
+
+ decision = dr.task_instance_scheduling_decisions(session=session)
+
+ # Simulate task_1 skipped
+ (ti_1,) = decision.schedulable_tis
+ ti_1.state = TaskInstanceState.SKIPPED
+ session.flush()
+
+ # Now task_2 in mapped tagk group is not expanded and also skipped..
Review Comment:
updated
--
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(task_instance): Ignore NotFullyPopulated if TriggerRule is not se… [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2472243606
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -286,30 +290,53 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
Review Comment:
Why not do `!= TriggerRule.ALL_SUCCESS` instead?
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485422979
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
but if we still want to change it to not success, I can do that as well :)
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #57474:
URL: https://github.com/apache/airflow/pull/57474
--
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(task_instance): Ignore NotFullyPopulated if the task might be triggered due to trigger rule setup [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #57474:
URL: https://github.com/apache/airflow/pull/57474#discussion_r2485427749
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -285,30 +289,55 @@ def ti_run(
def _get_upstream_map_indexes(
- task: MappedOperator | SerializedBaseOperator, ti_map_index: int, run_id: str, session: SessionDep
+ *,
+ serialized_dag: SerializedDAG,
+ ti: TI,
+ session: SessionDep,
) -> Iterator[tuple[str, int | list[int] | None]]:
- task_mapped_group = task.get_closest_mapped_task_group()
+ task = serialized_dag.get_task(ti.task_id)
for upstream_task in task.upstream_list:
- upstream_mapped_group = upstream_task.get_closest_mapped_task_group()
map_indexes: int | list[int] | None
- if upstream_mapped_group is None:
+ if (upstream_mapped_group := upstream_task.get_closest_mapped_task_group()) is None:
# regular tasks or non-mapped task groups
map_indexes = None
- elif task_mapped_group == upstream_mapped_group:
+ elif task.get_closest_mapped_task_group() == upstream_mapped_group:
# tasks in the same mapped task group hierarchy
- map_indexes = ti_map_index
+ map_indexes = ti.map_index
else:
# tasks not in the same mapped task group
# the upstream mapped task group should combine the return xcom as a list and return it
- mapped_ti_count: int
+ mapped_ti_count: int | None = None
+
try:
- # for cases that does not need to resolve xcom
+ # First try: without resolving XCom
mapped_ti_count = upstream_mapped_group.get_parse_time_mapped_ti_count()
except NotFullyPopulated:
- # for cases that needs to resolve xcom to get the correct count
- mapped_ti_count = cast(
- "SchedulerExpandInput", upstream_mapped_group._expand_input
- ).get_total_map_length(run_id, session=session)
+ # Second try: resolve XCom for correct count
+ try:
+ expand_input = cast("SchedulerExpandInput", upstream_mapped_group._expand_input)
+ mapped_ti_count = expand_input.get_total_map_length(ti.run_id, session=session)
+ except NotFullyPopulated:
+ # For these trigger rules, unresolved map indexes are acceptable.
+ # The success of the upstream task is not the main reason for triggering the current task.
+ # Therefore, whether the upstream task is fully populated can be ignored.
+ allowed_rules = {
+ TriggerRule.ALL_FAILED,
+ TriggerRule.ALL_DONE,
+ TriggerRule.ALL_DONE_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_DONE_SETUP_SUCCESS,
+ TriggerRule.ONE_SUCCESS,
+ TriggerRule.ONE_FAILED,
+ TriggerRule.ONE_DONE,
+ TriggerRule.NONE_FAILED,
+ TriggerRule.NONE_SKIPPED,
+ TriggerRule.ALWAYS,
+ TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS,
+ TriggerRule.ALL_SKIPPED,
+ }
+ if task.trigger_rule in allowed_rules:
+ mapped_ti_count = None
Review Comment:
or i can do some tweak on the test side.
--
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