thawk105 opened a new pull request, #45225:
URL: https://github.com/apache/airflow/pull/45225
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Enabling deferrable for HttpOperator causes an error.
The minimum test case is as follows
```
import datetime
from airflow import DAG
from airflow.operators.empty import EmptyOperator
from airflow.providers.http.operators.http import HttpOperator
with DAG(
dag_id="my_dag_name",
catchup=False,
) as dag:
test = HttpOperator(
task_id="test",
method="GET",
http_conn_id="google_http_default",
endpoint="search?q=airflow",
log_response=True,
deferrable=True,
)
EmptyOperator(task_id="start") >> test >> EmptyOperator(task_id="end")
```
For connections, set Connection Id to “google_http_default”, Connection Type
to “HTTP” and HOST to “https://www.google.com”.
If you place it in airflow/files/dags/ and run it you will get the following
error
```
[2024-12-27, 01:53:21 UTC] {taskinstance.py:3311} ERROR - Task failed with
exception
Traceback (most recent call last):
File "/opt/airflow/airflow/models/taskinstance.py", line 767, in
_execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow/models/taskinstance.py", line 733, in
_execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow/models/baseoperator.py", line 1814, in
resume_execution
return execute_callable(context)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow/providers/http/operators/http.py", line 261, in
execute_complete
raise AirflowException(f"Unexpected error in the operation:
{event['message']}")
airflow.exceptions.AirflowException: Unexpected error in the operation:
Connection closed.
```
Causes:.
https://github.com/apache/airflow/blob/9178f8f0b1ffd80b8eacf4d02b732528fde218e5/providers/src/airflow/providers/http/triggers/http
.py#L97
A session object is created by the above caller.
It is at the following link
https://github.com/apache/airflow/blob/9178f8f0b1ffd80b8eacf4d02b732528fde218e5/providers/src/airflow/providers/http/hooks/http.py
#L413
The following is then called.
https://github.com/apache/airflow/blob/9178f8f0b1ffd80b8eacf4d02b732528fde218e5/providers/src/airflow/providers/http/triggers/http
.py#L103
https://github.com/apache/airflow/blob/9178f8f0b1ffd80b8eacf4d02b732528fde218e5/providers/src/airflow/providers/http/triggers/http
.py#L117
It is expected that the ClientSession is alive at this point, but it is
already out of scope and disconnected.
To properly correct this, we changed the configuration to the following
Previously, the opposite was the case, which caused the bug.
Correct.
ClientSession scope {
ClientResponse scope{
response.read
}
}
Incorrect
ClientResponse scope {
ClientSession scope {
}
response.read expect session living (error)
}
With the interface changes, we modified the required tests, re-ran the
required tests, and verified that they completed successfully. I would be happy
to check and review! Best regards.
Takayuki Tanabe
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a
newsfragment file, named `{pr_number}.significant.rst` or
`{issue_number}.significant.rst`, in
[newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]