@@ -62,12 +62,13 @@ def poke(self, context: Context):
6262
6363
6464class DummyAsyncSensor (BaseSensorOperator ):
65- def __init__ (self , return_value = False , ** kwargs ):
65+ def __init__ (self , return_value = False , failure_exception : BaseException | None = None , ** kwargs ):
6666 super ().__init__ (** kwargs )
6767 self .return_value = return_value
68+ self .failure_exception = failure_exception or AirflowException ("Sensor failed" )
6869
6970 def execute_complete (self , context , event = None ):
70- raise AirflowException ( "Should be skipped" )
71+ raise self . failure_exception
7172
7273
7374class DummySensorWithXcomValue (BaseSensorOperator ):
@@ -688,16 +689,25 @@ def test_poke_mode_only_bad_poke(self):
688689
689690
690691class TestAsyncSensor :
692+ @pytest .mark .parametrize ("soft_fail" , [True , False ])
693+ def test_error_from_execute_complete_fails_regardless_of_soft_fail (self , soft_fail ):
694+ async_sensor = DummyAsyncSensor (task_id = "dummy_async_sensor" , soft_fail = soft_fail )
695+ with pytest .raises (AirflowException , match = "Sensor failed" ):
696+ async_sensor .resume_execution ("execute_complete" , None , {})
697+
691698 @pytest .mark .parametrize (
692- ( "soft_fail" , "expected_exception" ) ,
699+ "failure_exception" ,
693700 [
694- (True , AirflowSkipException ),
695- (False , AirflowException ),
701+ pytest .param (AirflowSensorTimeout ("timed out" ), id = "sensor-timeout" ),
702+ pytest .param (AirflowTaskTimeout ("timed out" ), id = "task-timeout" ),
703+ pytest .param (AirflowFailException ("failed" ), id = "fail-exception" ),
696704 ],
697705 )
698- def test_fail_after_resuming_deferred_sensor (self , soft_fail , expected_exception ):
699- async_sensor = DummyAsyncSensor (task_id = "dummy_async_sensor" , soft_fail = soft_fail )
700- with pytest .raises (expected_exception ):
706+ def test_soft_fail_skips_timeout_and_fail_exceptions_after_resuming (self , failure_exception ):
707+ async_sensor = DummyAsyncSensor (
708+ task_id = "dummy_async_sensor" , soft_fail = True , failure_exception = failure_exception
709+ )
710+ with pytest .raises (AirflowSkipException ):
701711 async_sensor .resume_execution ("execute_complete" , None , {})
702712
703713 @pytest .mark .parametrize (
@@ -727,25 +737,25 @@ def test_timeout_after_resuming_deferred_sensor_with_never_fail(self):
727737 context = {},
728738 )
729739
730- @pytest .mark .parametrize (
731- ("soft_fail" , "expected_exception" ),
732- [
733- (True , AirflowSkipException ),
734- (False , TaskDeferralError ),
735- ],
736- )
737- def test_trigger_failure_after_resuming_deferred_sensor_with_soft_fail (
738- self , soft_fail , expected_exception
739- ):
740- """Test that deferrable sensors with soft_fail skip on trigger failure instead of failing."""
740+ @pytest .mark .parametrize ("soft_fail" , [True , False ])
741+ def test_trigger_failure_after_resuming_deferred_sensor_fails_regardless_of_soft_fail (self , soft_fail ):
741742 async_sensor = DummyAsyncSensor (task_id = "dummy_async_sensor" , soft_fail = soft_fail )
742- with pytest .raises (expected_exception ):
743+ with pytest .raises (TaskDeferralError ):
743744 async_sensor .resume_execution (
744745 next_method = "__fail__" ,
745746 next_kwargs = {"error" : TriggerFailureReason .TRIGGER_FAILURE },
746747 context = {},
747748 )
748749
750+ def test_never_fail_keeps_the_skip_raised_by_execute_complete (self ):
751+ async_sensor = DummyAsyncSensor (
752+ task_id = "dummy_async_sensor" ,
753+ never_fail = True ,
754+ failure_exception = AirflowSkipException ("External job has skipped" ),
755+ )
756+ with pytest .raises (AirflowSkipException , match = "External job has skipped" ):
757+ async_sensor .resume_execution ("execute_complete" , None , {})
758+
749759 def test_trigger_failure_after_resuming_deferred_sensor_with_never_fail (self ):
750760 """Test that deferrable sensors with never_fail skip on trigger failure."""
751761 async_sensor = DummyAsyncSensor (task_id = "dummy_async_sensor" , never_fail = True )
0 commit comments