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

    <!-- 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: 
http://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.
   
   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: #62198
   * related: #62198
   -->
   
   ### Fix Scheduler Crash on Nullable 
[dag_version](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/tests/unit/jobs/test_scheduler_job.py:2811:4-2838:52)
 Access
   
   Fixes #62198
   
   The `TaskInstance.dag_version` field is nullable in the data model 
(specifically for tasks migrated from Airflow 2 to Airflow 3). However, several 
locations in the 
[SchedulerJobRunner](cci:2://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/src/airflow/jobs/scheduler_job_runner.py:218:0-3259:105)
 accessed `ti.dag_version.bundle_name` and `ti.dag_version.bundle_version` 
without null checks, leading to `AttributeError: 'NoneType' object has no 
attribute 'bundle_name'` and crashing the scheduler.
   
   This PR adds null checks to three critical locations in 
[scheduler_job_runner.py](cci:7://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/src/airflow/jobs/scheduler_job_runner.py:0:0-0:0):
   1. **Task Callback Execution**: In 
[process_executor_events](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/src/airflow/jobs/scheduler_job_runner.py:1022:4-1276:32),
 when an executor reports a task failure/retry that requires a callback.
   2. **Email Notifications**: In 
[process_executor_events](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/src/airflow/jobs/scheduler_job_runner.py:1022:4-1276:32),
 when a task failure triggers an email.
   3. **Stuck-in-Queued Handling**: In 
[_maybe_requeue_stuck_ti](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/src/airflow/jobs/scheduler_job_runner.py:2516:4-2587:37),
 when a task that has exceeded requeue attempts is marked as failed and 
requires a callback.
   
   **Approach**:
   When 
[dag_version](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/tests/unit/jobs/test_scheduler_job.py:2811:4-2838:52)
 is 
[None](cci:1://file:///c:/Users/Saksham%20Singhal/OneDrive/Desktop/Airflowww/airflow/airflow-core/tests/unit/jobs/test_scheduler_job.py:2281:4-2306:47),
 the scheduler now logs a warning and skips the callback/email request, rather 
than crashing. This mirrors the existing defensive pattern already implemented 
in the heartbeat timeout handler.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (just for guidence and logic)


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