Skip to content

Commit 78cdfa9

Browse files
Add handling for no metadata version
1 parent b0928f8 commit 78cdfa9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

policyengine/utils/data/caching_google_storage_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ def _get_latest_version(self, bucket: str, key: str) -> str | None:
2626
Get the latest version of a blob in the specified bucket and key.
2727
If no version is specified, return None.
2828
"""
29-
return (
30-
self.client.client.get_bucket(bucket)
31-
.get_blob(key)
32-
.metadata.get("version")
33-
)
29+
blob = self.client.client.get_bucket(bucket).get_blob(key)
30+
if blob.metadata is None:
31+
logging.warning(
32+
"No metadata found for blob, so it has no version attached."
33+
)
34+
return None
35+
else:
36+
return blob.metadata.get("version")
3437

3538
# To absolutely 100% avoid any possible issue with file corruption or thread contention
3639
# always replace the current target file with whatever we have cached as an atomic write.

0 commit comments

Comments
 (0)