Add a new argument for HttpSensor to accept a list of http status code to Continue Poking (#13499)
closes: #13451
diff --git a/airflow/providers/http/sensors/http.py b/airflow/providers/http/sensors/http.py
index c69859d..4ad6c12 100644
--- a/airflow/providers/http/sensors/http.py
+++ b/airflow/providers/http/sensors/http.py
@@ -29,7 +29,10 @@
404 Not Found or `response_check` returning False.
HTTP Error codes other than 404 (like 403) or Connection Refused Error
- would fail the sensor itself directly (no more poking).
+ would raise an exception and fail the sensor itself directly (no more poking).
+ To avoid failing the task for other codes than 404, the argument ``extra_option``
+ can be passed with the value ``{'check_response': False}``. It will make the ``response_check``
+ be execute for any http status code.
The response check can access the template context to the operator:
diff --git a/tests/providers/http/sensors/test_http.py b/tests/providers/http/sensors/test_http.py
index b14309f..569d235 100644
--- a/tests/providers/http/sensors/test_http.py
+++ b/tests/providers/http/sensors/test_http.py
@@ -64,6 +64,33 @@
task.execute(context={})
@patch("airflow.providers.http.hooks.http.requests.Session.send")
+ def test_poke_continues_for_http_500_with_extra_options_check_response_false(self, mock_session_send):
+ def resp_check(_):
+ return False
+
+ response = requests.Response()
+ response.status_code = 500
+ response.reason = 'Internal Server Error'
+ response._content = b'Internal Server Error'
+ mock_session_send.return_value = response
+
+ task = HttpSensor(
+ dag=self.dag,
+ task_id='http_sensor_poke_for_code_500',
+ http_conn_id='http_default',
+ endpoint='',
+ request_params={},
+ method='HEAD',
+ response_check=resp_check,
+ extra_options={'check_response': False},
+ timeout=5,
+ poke_interval=1,
+ )
+
+ with self.assertRaises(AirflowSensorTimeout):
+ task.execute(context={})
+
+ @patch("airflow.providers.http.hooks.http.requests.Session.send")
def test_head_method(self, mock_session_send):
def resp_check(_):
return True