Skip to content
Permalink
Browse files
fix: downloading no longer marks metadata fields as 'changed' (#523)
  • Loading branch information
andrewsg committed Jul 23, 2021
1 parent c5f4ad8 commit 160d1ecb41f1f269b25cb68b2d2f7daf418bf01c
Showing with 17 additions and 7 deletions.
  1. +15 −7 google/cloud/storage/blob.py
  2. +2 −0 tests/unit/test_blob.py
@@ -875,11 +875,19 @@ def _extract_headers_from_download(self, response):
:class requests.models.Response
:param response: The server response from downloading a non-chunked file
"""
self.content_encoding = response.headers.get("Content-Encoding", None)
self.content_type = response.headers.get("Content-Type", None)
self.cache_control = response.headers.get("Cache-Control", None)
self.storage_class = response.headers.get("X-Goog-Storage-Class", None)
self.content_language = response.headers.get("Content-Language", None)
self._properties["contentEncoding"] = response.headers.get(
"Content-Encoding", None
)
self._properties[_CONTENT_TYPE_FIELD] = response.headers.get(
"Content-Type", None
)
self._properties["cacheControl"] = response.headers.get("Cache-Control", None)
self._properties["storageClass"] = response.headers.get(
"X-Goog-Storage-Class", None
)
self._properties["contentLanguage"] = response.headers.get(
"Content-Language", None
)
self._properties["etag"] = response.headers.get("ETag", None)
self._properties["generation"] = response.headers.get("X-goog-generation", None)
self._properties["metageneration"] = response.headers.get(
@@ -896,8 +904,8 @@ def _extract_headers_from_download(self, response):
method, digest = match.groups()
digests[method] = digest

self.crc32c = digests.get("crc32c", None)
self.md5_hash = digests.get("md5", None)
self._properties["crc32c"] = digests.get("crc32c", None)
self._properties["md5Hash"] = digests.get("md5", None)

def _do_download(
self,
@@ -1090,6 +1090,7 @@ def test__extract_headers_from_download_gzipped(self):
self.assertEqual(blob.etag, "kittens")
self.assertEqual(blob.generation, 42)
self.assertEqual(blob.metageneration, 4)
self.assertEqual(blob._changes, set())

def test__extract_headers_from_download_empty(self):
blob_name = "blob-name"
@@ -1120,6 +1121,7 @@ def test__extract_headers_from_download_empty(self):
self.assertEqual(blob.etag, "kittens")
self.assertEqual(blob.generation, 42)
self.assertEqual(blob.metageneration, 4)
self.assertEqual(blob._changes, set())

def test__extract_headers_from_download_w_hash_response_header_none(self):
blob_name = "blob-name"

0 comments on commit 160d1ec

Please sign in to comment.