This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new a7132cce963 Log the HTTP response in HttpToGCSOperator when
log_response is set (#72952)
a7132cce963 is described below
commit a7132cce963295276e4e83c3d383342f8c872dd8
Author: Bingqin Wang <[email protected]>
AuthorDate: Sun Sep 20 14:09:42 2026 -0500
Log the HTTP response in HttpToGCSOperator when log_response is set (#72952)
`HttpToGCSOperator` documents `log_response` ("Log the response (default:
False)") and stores it, but `execute()` never reads it, so the response body is
never logged no matter what the user sets. This logs `response.text` after the
request when the flag is set, the same way `HttpOperator` does.
**Changes**
-
`providers/google/src/airflow/providers/google/cloud/transfers/http_to_gcs.py`:
log the response text when `log_response` is true
- `providers/google/tests/unit/google/cloud/transfers/test_http_to_gcs.py`:
`test_execute_logs_response_only_when_requested`, parametrized over both values
**Testing**
- `providers/google`:
`tests/unit/google/cloud/transfers/test_http_to_gcs.py`
- mypy on the changed module, prek hooks on the changed files
---
.../google/cloud/transfers/http_to_gcs.py | 2 ++
.../google/cloud/transfers/test_http_to_gcs.py | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git
a/providers/google/src/airflow/providers/google/cloud/transfers/http_to_gcs.py
b/providers/google/src/airflow/providers/google/cloud/transfers/http_to_gcs.py
index 39748d68150..62b5213d2aa 100644
---
a/providers/google/src/airflow/providers/google/cloud/transfers/http_to_gcs.py
+++
b/providers/google/src/airflow/providers/google/cloud/transfers/http_to_gcs.py
@@ -176,6 +176,8 @@ class HttpToGCSOperator(BaseOperator):
response = self.http_hook.run(
endpoint=self.endpoint, data=self.data, headers=self.headers,
extra_options=self.extra_options
)
+ if self.log_response:
+ self.log.info(response.text)
self.log.info("Uploading to GCS")
self.gcs_hook.upload(
diff --git
a/providers/google/tests/unit/google/cloud/transfers/test_http_to_gcs.py
b/providers/google/tests/unit/google/cloud/transfers/test_http_to_gcs.py
index 6976afe6ef6..e19b76abae8 100644
--- a/providers/google/tests/unit/google/cloud/transfers/test_http_to_gcs.py
+++ b/providers/google/tests/unit/google/cloud/transfers/test_http_to_gcs.py
@@ -19,6 +19,8 @@ from __future__ import annotations
from unittest import mock
+import pytest
+
from airflow.providers.google.cloud.transfers.http_to_gcs import
HttpToGCSOperator
TASK_ID = "test-http-to-gcs-operator"
@@ -125,3 +127,23 @@ class TestHttpToGCSOperator:
expected_uris = f"gs://{TEST_BUCKET}/{DESTINATION_PATH_FILE}"
assert result == [expected_uris]
+
+ @pytest.mark.parametrize("log_response", [True, False])
+ @mock.patch("airflow.providers.google.cloud.transfers.http_to_gcs.GCSHook")
+
@mock.patch("airflow.providers.google.cloud.transfers.http_to_gcs.HttpHook")
+ def test_execute_logs_response_only_when_requested(self, http_hook,
gcs_hook, log_response):
+ http_hook.return_value.run.return_value.text = "response body"
+ task = HttpToGCSOperator(
+ task_id=TASK_ID,
+ http_conn_id=HTTP_CONN_ID,
+ endpoint=ENDPOINT,
+ object_name=DESTINATION_PATH_FILE,
+ bucket_name=TEST_BUCKET,
+ gcp_conn_id=GCP_CONN_ID,
+ log_response=log_response,
+ )
+
+ with mock.patch.object(task.log, "info") as mock_info:
+ task.execute(None)
+
+ assert (mock.call("response body") in mock_info.call_args_list) is
log_response