Skip to content

Deferrable HttpSensor does not move to Triggerer when using response_check #40209

Open

Description

@josh-fell

Discussed in #39597

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?

Activity

  1. josh-fell commented on Jun 18, 2024

    @josh-fell
    ContributorAuthor

    Probably what the solution should be. May need to confirm with HttpOperator too:

    #39597 (comment)

  2. added
    contributors-workshop
    on Sep 11, 2024
  3. kandharvishnu commented on Oct 23, 2024

    @kandharvishnu
    Contributor

    I would like to work on this issue

  4. dabla commented on Mar 11, 2025

    @dabla
    Contributor

    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,
    )
    
  5. k4rtikp4til commented on Aug 6, 2025

    @k4rtikp4til

    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",
        )`
    
  6. dabla commented on Aug 6, 2025

    @dabla
    Contributor

    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.

  7. github-actions commented on Aug 23, 2026

    @github-actions
    Contributor

    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.

  8. removed
    contributors-workshop
    on Aug 30, 2026
  9. added
    needs-triage
    and removed on Aug 30, 2026
  10. removed
    needs-triage
    on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions