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/05/19 14:48:32 UTC

[PR] feat: fail a task in scheduling phase if there's an inactive inlet or outlet [airflow]

Lee-W opened a new pull request, #50773:
URL: https://github.com/apache/airflow/pull/50773

   … 
   
   <!--
    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] Add back invalid inlet and outlet check before running tasks [airflow]

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

   The logic is ready, but I still need some test cases and code polish. I would appreciate an early review. If not, I think I'll be able to wrap it up tomorrow


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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

   > > This does not explain why the task takes five minutes to fail. It avoids the task to run altogether, but masks the underlying issue (still unknown) why the task fails so slowly.
   > 
   > The task execution was skipped as it's an empty operator, and the checking at a later stage in the task SDK was not handled, which breaks the API server. I think why it fails slow is due to the broken API server
   
   This is now guarded as well in case assets somehow become inactive during task execution


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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

   As it has been approved and we're about to start work on releasing 3.0.2, I will merge this one.


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #50773:
URL: https://github.com/apache/airflow/pull/50773#discussion_r2122747650


##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -897,7 +897,8 @@ def test_run_with_asset_outlets(
     instant = timezone.datetime(2024, 12, 3, 10, 0)
     time_machine.move_to(instant, tick=False)
 
-    run(ti, context=ti.get_template_context(), log=mock.MagicMock())
+    with mock.patch("airflow.sdk.execution_time.task_runner._validate_task_inlets_and_outlets"):
+        run(ti, context=ti.get_template_context(), log=mock.MagicMock())

Review Comment:
   Can we please also assert that the mock was called?



##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -791,6 +796,22 @@ def _prepare(ti: RuntimeTaskInstance, log: Logger, context: Context) -> ToSuperv
     return None
 
 
+def _validate_task_inlets_and_outlets(*, ti: RuntimeTaskInstance, log: Logger) -> None:
+    if not ti.task.inlets and not ti.task.outlets:
+        return
+
+    SUPERVISOR_COMMS.send_request(msg=ValidateInletsAndOutlets(ti_id=ti.id), log=log)
+    inactive_assets_resp = SUPERVISOR_COMMS.get_message()
+    if TYPE_CHECKING:
+        assert isinstance(inactive_assets_resp, InactiveAssetsResult)
+    if inactive_assets := inactive_assets_resp.inactive_assets:
+        raise AirflowInactiveAssetInInletOrOutletException(
+            inactive_asset_keys=[
+                AssetUniqueKey.from_profile(asset_profile) for asset_profile in inactive_assets
+            ]
+        )

Review Comment:
   Interesting why or how this was removed. But as I understand it, this part checks "before" running if its possible to run with the current asset settings right?



##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1215,6 +1217,10 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
             )
         elif isinstance(msg, DeleteVariable):
             resp = self.client.variables.delete(msg.key)
+        elif isinstance(msg, ValidateInletsAndOutlets):

Review Comment:
   Could you add a test under: `test_handle_requests` in test_supervisor.py?



##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -400,12 +407,16 @@ def ti_update_state(
         query = TI.duration_expression_update(ti_patch_payload.end_date, query, session.bind)
         updated_state = ti_patch_payload.state
         task_instance = session.get(TI, ti_id_str)
-        TI.register_asset_changes_in_db(
-            task_instance,
-            ti_patch_payload.task_outlets,  # type: ignore
-            ti_patch_payload.outlet_events,
-            session,
-        )
+        try:
+            TI.register_asset_changes_in_db(
+                task_instance,
+                ti_patch_payload.task_outlets,  # type: ignore
+                ti_patch_payload.outlet_events,
+                session,
+            )
+        except AirflowInactiveAssetInInletOrOutletException:
+            log.exception()

Review Comment:
   ```suggestion
   except AirflowInactiveAssetInInletOrOutletException as e:
       log.error("Asset registration failed due to conflicting asset: %s", e)
   ```



-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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

   > This does not explain why the task takes five minutes to fail. It avoids the task to run altogether, but masks the underlying issue (still unknown) why the task fails so slowly.
   
   The task execution was skipped as it's an empty operator, and the checking at a later stage in the task SDK was not handled, which breaks the API server. I think why it fails slow is due to the broken API server


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #50773:
URL: https://github.com/apache/airflow/pull/50773#discussion_r2122884063


##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -791,6 +796,22 @@ def _prepare(ti: RuntimeTaskInstance, log: Logger, context: Context) -> ToSuperv
     return None
 
 
+def _validate_task_inlets_and_outlets(*, ti: RuntimeTaskInstance, log: Logger) -> None:
+    if not ti.task.inlets and not ti.task.outlets:
+        return
+
+    SUPERVISOR_COMMS.send_request(msg=ValidateInletsAndOutlets(ti_id=ti.id), log=log)
+    inactive_assets_resp = SUPERVISOR_COMMS.get_message()
+    if TYPE_CHECKING:
+        assert isinstance(inactive_assets_resp, InactiveAssetsResult)
+    if inactive_assets := inactive_assets_resp.inactive_assets:
+        raise AirflowInactiveAssetInInletOrOutletException(
+            inactive_asset_keys=[
+                AssetUniqueKey.from_profile(asset_profile) for asset_profile in inactive_assets
+            ]
+        )

Review Comment:
   Ah maybe it was a mistake, while wiping out the old way of doing things (ti.run())
   
   But thats not really related. 



-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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

   This does not explain why the task takes five minutes to fail. It avoids the task to run altogether, but masks the underlying issue (still unknown) why the task fails so slowly.


-- 
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 back invalid inlet and outlet check before running tasks [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #50773:
URL: https://github.com/apache/airflow/pull/50773#discussion_r2122806786


##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -791,6 +796,22 @@ def _prepare(ti: RuntimeTaskInstance, log: Logger, context: Context) -> ToSuperv
     return None
 
 
+def _validate_task_inlets_and_outlets(*, ti: RuntimeTaskInstance, log: Logger) -> None:
+    if not ti.task.inlets and not ti.task.outlets:
+        return
+
+    SUPERVISOR_COMMS.send_request(msg=ValidateInletsAndOutlets(ti_id=ti.id), log=log)
+    inactive_assets_resp = SUPERVISOR_COMMS.get_message()
+    if TYPE_CHECKING:
+        assert isinstance(inactive_assets_resp, InactiveAssetsResult)
+    if inactive_assets := inactive_assets_resp.inactive_assets:
+        raise AirflowInactiveAssetInInletOrOutletException(
+            inactive_asset_keys=[
+                AssetUniqueKey.from_profile(asset_profile) for asset_profile in inactive_assets
+            ]
+        )

Review Comment:
   don't really know why 🤔 but this is how https://github.com/apache/airflow/pull/50141/files#diff-f660147b2482fe9eb7c256a6e9b5c0d8c0623fc31beaf5048e476e9bd1b7823bL1735



##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -791,6 +796,22 @@ def _prepare(ti: RuntimeTaskInstance, log: Logger, context: Context) -> ToSuperv
     return None
 
 
+def _validate_task_inlets_and_outlets(*, ti: RuntimeTaskInstance, log: Logger) -> None:
+    if not ti.task.inlets and not ti.task.outlets:
+        return
+
+    SUPERVISOR_COMMS.send_request(msg=ValidateInletsAndOutlets(ti_id=ti.id), log=log)
+    inactive_assets_resp = SUPERVISOR_COMMS.get_message()
+    if TYPE_CHECKING:
+        assert isinstance(inactive_assets_resp, InactiveAssetsResult)
+    if inactive_assets := inactive_assets_resp.inactive_assets:
+        raise AirflowInactiveAssetInInletOrOutletException(
+            inactive_asset_keys=[
+                AssetUniqueKey.from_profile(asset_profile) for asset_profile in inactive_assets
+            ]
+        )

Review Comment:
   Yes



-- 
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 back invalid inlet and outlet check before running tasks [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #50773:
URL: https://github.com/apache/airflow/pull/50773#discussion_r2122807166


##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -897,7 +897,8 @@ def test_run_with_asset_outlets(
     instant = timezone.datetime(2024, 12, 3, 10, 0)
     time_machine.move_to(instant, tick=False)
 
-    run(ti, context=ti.get_template_context(), log=mock.MagicMock())
+    with mock.patch("airflow.sdk.execution_time.task_runner._validate_task_inlets_and_outlets"):
+        run(ti, context=ti.get_template_context(), log=mock.MagicMock())

Review Comment:
   sure



##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1215,6 +1217,10 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
             )
         elif isinstance(msg, DeleteVariable):
             resp = self.client.variables.delete(msg.key)
+        elif isinstance(msg, ValidateInletsAndOutlets):

Review Comment:
   sure



-- 
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 back invalid inlet and outlet check before running tasks [airflow]

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

   @amoghrajesh addressed all the comments. Could you please check again? Thanks!


-- 
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