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

   <!--
    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/
   -->
   
   Only last 2 commits are relevant.
   
   Dependent on https://github.com/apache/airflow/pull/44977 and hence on 
https://github.com/apache/airflow/pull/44954.
   Handling the case of `up_for_retry` from the task SDK.
   
   This exception can be thrown in multiple cases, two valid examples are:
   
   1. I have a dag which times out in 1 second but the task sleeps for 100 
seconds, it will end up throwing the `AirflowTaskTimeout` exception:
   ```
   import sys
   from time import sleep
   
   from airflow import DAG
   from airflow.providers.standard.operators.python import PythonOperator
   from datetime import datetime, timedelta
   
   from airflow.sdk.definitions.baseoperator import AirflowException
   
   
   def print_hello():
       sleep(100)
   
   with DAG(
       dag_id="hello_world_single_task",
       default_args={
           "owner": "airflow",
           "depends_on_past": False,
           "retries": 1,
       },
       description="A simple Hello World DAG with one task",
       schedule=None,
       start_date=datetime(2024, 1, 1),
       catchup=False,
       tags=["example"],
   ) as dag:
       hello_task = PythonOperator(
           retries=1,
           task_id="say_hello",
           execution_timeout=timedelta(seconds=1),
           python_callable=print_hello,
       )
   ```
   Should be marked with `up_for_retry`
   <img width="1722" alt="image" 
src="https://github.com/user-attachments/assets/8de40ddb-0bfb-4faa-a02e-5a6567570e15";
 />
   
   
   2. A task raises the `AirflowException` 
   Example: If we are unable to render the pod template for K8s while using 
K8sExecutor with Airflow.
   ```
   @provide_session
   def get_rendered_k8s_spec(task_instance: TaskInstance, session=NEW_SESSION) 
-> dict | None:
       """Fetch rendered template fields from DB."""
       from airflow.models.renderedtifields import RenderedTaskInstanceFields
   
       rendered_k8s_spec = 
RenderedTaskInstanceFields.get_k8s_pod_yaml(task_instance, session=session)
       if not rendered_k8s_spec:
           try:
               rendered_k8s_spec = render_k8s_pod_yaml(task_instance)
           except (TemplateAssertionError, UndefinedError) as e:
               raise AirflowException(f"Unable to render a k8s spec for this 
taskinstance: {e}") from e
       return rendered_k8s_spec
   ```
   
   
   Key changes:
   1. This PR adds the `up_for_retry` state into `TerminalTIState` as it is a 
terminal state and on hitting this state, anything additional work apart from 
marking it to that state needn't be done.
   2. Called the API from task runner when AirflowTaskTimeout, AirflowException 
is raised.
   
   
   
   
   <!-- 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 
[newsfragments](https://github.com/apache/airflow/tree/main/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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to