Skip to content

Commit

Permalink
Fix cache_control parameter of upload function in GCSHook (#32440)
Browse files Browse the repository at this point in the history
* Fix `cache_control` parameter of upload function in `GCSHook`
---------

Co-authored-by: Ying Wu <ying-w@users.noreply.github.com>
  • Loading branch information
shahar1 and ying-w committed Jul 8, 2023
1 parent 2571367 commit e70bee0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/providers/google/cloud/hooks/gcs.py
Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions tests/providers/google/cloud/hooks/test_gcs.py
Expand Up @@ -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"
Expand Down

0 comments on commit e70bee0

Please sign in to comment.