You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deferrable HttpSensor does not move to Triggerer when using response_check #40209
Originally posted by bejota May 13, 2024
Hello,
I'm using HttpSensor to poll SLURM's REST API for job status. I'm using deferrable mode with response_check. The task only goes to the triggerer if I remove the response_check.
Airflow Docker Image apache/airflow:latest-python3.9
Airflow Version 2.9.0
apache-airflow-providers-http 4.10.0
Does not move to triggerer:
check_slurm_job = HttpSensor(
task_id="check_slurm_job",
http_conn_id="slurm_conn_id",
method="get",
endpoint="slurm/v0.0.40/job/999",
response_check=lambda response: "COMPLETED" in response.text,
poke_interval=10,
timeout=60 * 60 * 5,
deferrable=True, # not deferring to triggerer ?
dag=dag,
)
Moves to triggerer:
check_slurm_job = HttpSensor(
task_id="check_slurm_job",
http_conn_id="slurm_conn_id",
method="get",
endpoint="slurm/v0.0.40/job/999",
# response_check=lambda response: "COMPLETED" in response.text,
poke_interval=10,
timeout=60 * 60 * 5,
deferrable=True, # not deferring to triggerer ?
dag=dag,
)
In digging further, I see that HttpTrigger has no response_check method. I will attempt to add one, unless there is a better approach to this problem?
I think for the check_response to be taken into account, you need to pass extra_options={"check_response": False},
otherwise the check_response parameter won't be taken into account.
I've created a PR for this to allow to configure this also within extra of your http connection.
So maybe try this, if this doesn't work the a PR will be needed:
check_slurm_job = HttpSensor(
task_id="check_slurm_job",
http_conn_id="slurm_conn_id",
method="get",
endpoint="slurm/v0.0.40/job/999",
response_check=lambda response: "COMPLETED" in response.text,
poke_interval=10,
timeout=60 * 60 * 5,
deferrable=True, # not deferring to triggerer ?
extra_options={"check_response": False},
dag=dag,
)
Hey @dabla – I looked into your PR that was merged related to this issue. Curious to understand: what was the motivation for moving the response_check logic to the connection level?
In my case, I’m generating DAGs dynamically via Jinja templates based on user input. Each connection acts as a root, and I dynamically attach endpoints and response_check functions per task. So, binding response_check at the connection level isn’t ideal for this setup, and I'm still running into the same issue described here.
For anyone else facing this, here’s the workaround I’m using for now:
`class DeferredHttpPollingSensor(HttpSensor):
"""
Custom HttpSensor that defers the polling if the response is not ready.
"""
def __init__(self, *args, **kwargs):
"""Initialize the DeferredHttpPollingSensor."""
kwargs["deferrable"] = True
super().__init__(*args, **kwargs)
def execute(self, context: Context):
"""Execute the sensor."""
# Store the start time for timeout tracking
context["ti"].xcom_push(
key="deferred_http_polling_sensor_start", value=datetime.now().isoformat()
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)
def execute_complete(self, context: Context, event=None):
"""Execute the complete sensor."""
# Check timeout
start_time_str = context["ti"].xcom_pull(key="deferred_http_polling_sensor_start")
if start_time_str:
start_time = datetime.fromisoformat(start_time_str)
elapsed_time = (datetime.now() - start_time).total_seconds()
if elapsed_time >= self.timeout:
raise AirflowSensorTimeout(
f"Snap. Time is OUT. DAG: {context['dag'].dag_id}, "
f"Task: {context['task'].task_id}, "
f"Duration: {elapsed_time}s, "
f"Timeout: {self.timeout}s"
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)`
Hey @dabla – I looked into your PR that was merged related to this issue. Curious to understand: what was the motivation for moving the response_check logic to the connection level?
In my case, I’m generating DAGs dynamically via Jinja templates based on user input. Each connection acts as a root, and I dynamically attach endpoints and response_check functions per task. So, binding response_check at the connection level isn’t ideal for this setup, and I'm still running into the same issue described here.
For anyone else facing this, here’s the workaround I’m using for now:
`class DeferredHttpPollingSensor(HttpSensor): """ Custom HttpSensor that defers the polling if the response is not ready. """
def __init__(self, *args, **kwargs):
"""Initialize the DeferredHttpPollingSensor."""
kwargs["deferrable"] = True
super().__init__(*args, **kwargs)
def execute(self, context: Context):
"""Execute the sensor."""
# Store the start time for timeout tracking
context["ti"].xcom_push(
key="deferred_http_polling_sensor_start", value=datetime.now().isoformat()
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)
def execute_complete(self, context: Context, event=None):
"""Execute the complete sensor."""
# Check timeout
start_time_str = context["ti"].xcom_pull(key="deferred_http_polling_sensor_start")
if start_time_str:
start_time = datetime.fromisoformat(start_time_str)
elapsed_time = (datetime.now() - start_time).total_seconds()
if elapsed_time >= self.timeout:
raise AirflowSensorTimeout(
f"Snap. Time is OUT. DAG: {context['dag'].dag_id}, "
f"Task: {context['task'].task_id}, "
f"Duration: {elapsed_time}s, "
f"Timeout: {self.timeout}s"
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)`
Hey @dabla – I looked into your PR that was merged related to this issue. Curious to understand: what was the motivation for moving the response_check logic to the connection level?
In my case, I’m generating DAGs dynamically via Jinja templates based on user input. Each connection acts as a root, and I dynamically attach endpoints and response_check functions per task. So, binding response_check at the connection level isn’t ideal for this setup, and I'm still running into the same issue described here.
For anyone else facing this, here’s the workaround I’m using for now:
`class DeferredHttpPollingSensor(HttpSensor): """ Custom HttpSensor that defers the polling if the response is not ready. """
def __init__(self, *args, **kwargs):
"""Initialize the DeferredHttpPollingSensor."""
kwargs["deferrable"] = True
super().__init__(*args, **kwargs)
def execute(self, context: Context):
"""Execute the sensor."""
# Store the start time for timeout tracking
context["ti"].xcom_push(
key="deferred_http_polling_sensor_start", value=datetime.now().isoformat()
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)
def execute_complete(self, context: Context, event=None):
"""Execute the complete sensor."""
# Check timeout
start_time_str = context["ti"].xcom_pull(key="deferred_http_polling_sensor_start")
if start_time_str:
start_time = datetime.fromisoformat(start_time_str)
elapsed_time = (datetime.now() - start_time).total_seconds()
if elapsed_time >= self.timeout:
raise AirflowSensorTimeout(
f"Snap. Time is OUT. DAG: {context['dag'].dag_id}, "
f"Task: {context['task'].task_id}, "
f"Duration: {elapsed_time}s, "
f"Timeout: {self.timeout}s"
)
if self.poke(context):
return True
self.defer(
trigger=TimeDeltaTrigger(delta=timedelta(seconds=self.poke_interval)),
method_name="execute_complete",
)`
Hello @k4rtikp4til, the issue is still open and my PR didn’t get merged yet, so to me it seems normal that you still run into this issue.
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
Activity
josh-fell commentedon Jun 18, 2024
Probably what the solution should be. May need to confirm with
HttpOperatortoo:#39597 (comment)
kandharvishnu commentedon Oct 23, 2024
I would like to work on this issue
dabla commentedon Mar 11, 2025
I think for the check_response to be taken into account, you need to pass extra_options={"check_response": False},
otherwise the check_response parameter won't be taken into account.
I've created a PR for this to allow to configure this also within extra of your http connection.
So maybe try this, if this doesn't work the a PR will be needed:
k4rtikp4til commentedon Aug 6, 2025
Hey @dabla – I looked into your PR that was merged related to this issue. Curious to understand: what was the motivation for moving the response_check logic to the connection level?
In my case, I’m generating DAGs dynamically via Jinja templates based on user input. Each connection acts as a root, and I dynamically attach endpoints and response_check functions per task. So, binding response_check at the connection level isn’t ideal for this setup, and I'm still running into the same issue described here.
For anyone else facing this, here’s the workaround I’m using for now:
`class DeferredHttpPollingSensor(HttpSensor):
"""
Custom HttpSensor that defers the polling if the response is not ready.
"""
dabla commentedon Aug 6, 2025
Hello @k4rtikp4til, the issue is still open and my PR didn’t get merged yet, so to me it seems normal that you still run into this issue.
github-actions commentedon Aug 23, 2026
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.