From e70bee00cd12ecf1462485a747c0e3296ef7d48c Mon Sep 17 00:00:00 2001 From: Shahar Epstein <60007259+shahar1@users.noreply.github.com> Date: Sat, 8 Jul 2023 14:05:23 +0300 Subject: [PATCH] Fix `cache_control` parameter of upload function in `GCSHook` (#32440) * Fix `cache_control` parameter of upload function in `GCSHook` --------- Co-authored-by: Ying Wu --- airflow/providers/google/cloud/hooks/gcs.py | 2 +- tests/providers/google/cloud/hooks/test_gcs.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/airflow/providers/google/cloud/hooks/gcs.py b/airflow/providers/google/cloud/hooks/gcs.py index 42a27e80f898..5350c9f79012 100644 --- a/airflow/providers/google/cloud/hooks/gcs.py +++ b/airflow/providers/google/cloud/hooks/gcs.py @@ -517,7 +517,7 @@ def _call_with_retry(f: Callable[[], None]) -> None: blob.metadata = metadata if cache_control: - blob.cacheControl = cache_control + blob.cache_control = cache_control if filename and data: raise ValueError( diff --git a/tests/providers/google/cloud/hooks/test_gcs.py b/tests/providers/google/cloud/hooks/test_gcs.py index 9e7ff971d2ba..61ce7a416271 100644 --- a/tests/providers/google/cloud/hooks/test_gcs.py +++ b/tests/providers/google/cloud/hooks/test_gcs.py @@ -936,6 +936,19 @@ def test_upload_file(self, mock_service, testdata_file): assert metadata == blob_object.return_value.metadata + @mock.patch(GCS_STRING.format("GCSHook.get_conn")) + def test_upload_cache_control(self, mock_service, testdata_file): + test_bucket = "test_bucket" + test_object = "test_object" + cache_control = "public, max-age=3600" + + bucket_mock = mock_service.return_value.bucket + blob_object = bucket_mock.return_value.blob + + self.gcs_hook.upload(test_bucket, test_object, filename=testdata_file, cache_control=cache_control) + + assert cache_control == blob_object.return_value.cache_control + @mock.patch(GCS_STRING.format("GCSHook.get_conn")) def test_upload_file_gzip(self, mock_service, testdata_file): test_bucket = "test_bucket"