Skip to content

Fix deferrable sensors not respecting soft_fail on timeout#61132

Merged
kaxil merged 2 commits into
apache:mainfrom
king:fix-deferrable-sensor-soft-fail-timeout
Feb 4, 2026
Merged

Fix deferrable sensors not respecting soft_fail on timeout#61132
kaxil merged 2 commits into
apache:mainfrom
king:fix-deferrable-sensor-soft-fail-timeout

Conversation

@nathadfield

@nathadfield nathadfield commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

closes: #61130

Description

Fixes a regression in Airflow 3.x where deferrable sensors with soft_fail=True fail with AirflowSensorTimeout instead of being marked as SKIPPED when they timeout. This breaks compatibility with Airflow 2.x behavior and user expectations.

Root Cause

In BaseSensorOperator.resume_execution(), the exception handling order was incorrect:

  1. TaskDeferralTimeout was caught and immediately converted to AirflowSensorTimeout
  2. The soft_fail/never_fail checks only caught AirflowException and TaskDeferralError
  3. By the time these checks ran, the timeout was already converted, causing the flags to be ignored

Solution

  • Use nested try-except blocks to convert TaskDeferralTimeoutAirflowSensorTimeout while ensuring both exceptions are caught by the outer handler
  • Check soft_fail and never_fail flags before raising AirflowSensorTimeout
  • Align error messages with the execute() method for consistency

Changes

task-sdk/src/airflow/sdk/bases/sensor.py:

  • Modified resume_execution() to use nested exception handling
  • Changed to separate soft_fail and never_fail checks with explicit error messages

task-sdk/tests/task_sdk/bases/test_sensor.py:

  • Added tests for timeout scenarios with soft_fail=True/False
  • Added tests for timeout scenarios with never_fail=True
  • Added tests for trigger failure scenarios with soft_fail=True/False
  • Added tests for trigger failure scenarios with never_fail=True
  • Fixed existing tests to use TriggerFailureReason enum values
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid overall. Good handling of the nested try/except and the tests cover the full policy matrix.

I just have one suggestion that I have mentioned below.

Comment thread task-sdk/src/airflow/sdk/bases/sensor.py
nathadfield and others added 2 commits January 28, 2026 10:00
When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@nathadfield nathadfield force-pushed the fix-deferrable-sensor-soft-fail-timeout branch from 0ece79a to ef1aa5e Compare January 28, 2026 10:00
@nathadfield

Copy link
Copy Markdown
Contributor Author

Hey folks! If any of you get the time to review this PR soon I'd be most appreciative. Many thanks!

@nathadfield nathadfield added this to the Airflow 3.1.8 milestone Feb 2, 2026
@kaxil kaxil merged commit cec8ba6 into apache:main Feb 4, 2026
100 checks passed
github-actions Bot pushed a commit that referenced this pull request Feb 4, 2026
#61132)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: #61130
(cherry picked from commit cec8ba6)

Co-authored-by: Nathan Hadfield <[email protected]>
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Feb 4, 2026
apache#61132)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130
(cherry picked from commit cec8ba6)

Co-authored-by: Nathan Hadfield <[email protected]>
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@nathadfield nathadfield deleted the fix-deferrable-sensor-soft-fail-timeout branch February 4, 2026 13:42
Alok-kumar-priyadarshi pushed a commit to Alok-kumar-priyadarshi/airflow that referenced this pull request Feb 5, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
jhgoebbert pushed a commit to jhgoebbert/airflow_Owen-CH-Leung that referenced this pull request Feb 8, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
potiuk pushed a commit that referenced this pull request Feb 18, 2026
#61132) (#61421)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: #61130
(cherry picked from commit cec8ba6)

Co-authored-by: Nathan Hadfield <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Subham-KRLX pushed a commit to Subham-KRLX/airflow that referenced this pull request Mar 4, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
vatsrahul1001 pushed a commit that referenced this pull request Mar 4, 2026
#61132) (#61421)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: #61130
(cherry picked from commit cec8ba6)

Co-authored-by: Nathan Hadfield <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
radhwene pushed a commit to radhwene/airflow that referenced this pull request Mar 21, 2026
)

When a deferrable sensor with soft_fail=True times out, the task
fails with AirflowSensorTimeout instead of being marked as SKIPPED.
This is a regression from Airflow 2.x behavior.

The issue was in resume_execution() where TaskDeferralTimeout was
converted to AirflowSensorTimeout before checking soft_fail. This
fix uses nested exception handling to check soft_fail and never_fail
before the conversion, ensuring timeouts are properly skipped.

closes: apache#61130

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deferrable sensors fail to respect soft_fail=True on timeout

3 participants