From 06df320f5d44482ef3cd3a4dccc81aa8c882e41c Mon Sep 17 00:00:00 2001 From: oittaa <8972248+oittaa@users.noreply.github.com> Date: Mon, 31 Jan 2022 08:33:11 +0100 Subject: [PATCH 1/2] Use blob.time_created https://googleapis.dev/python/storage/latest/blobs.html#google.cloud.storage.blob.Blob.time_created --- django_gcloud_storage/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/django_gcloud_storage/__init__.py b/django_gcloud_storage/__init__.py index c2cba36..6a42934 100644 --- a/django_gcloud_storage/__init__.py +++ b/django_gcloud_storage/__init__.py @@ -185,11 +185,7 @@ def created_time(self, name): blob = self.bucket.get_blob(name) - # google.cloud doesn't provide a public method for this - value = blob._properties.get("timeCreated", None) - if value is not None: - naive = datetime.datetime.strptime(value, gcloud_helpers._RFC3339_MICROS) - return naive.replace(tzinfo=gcloud_helpers.UTC) + return blob.time_created if blob else None def delete(self, name): name = safe_join(self.bucket_subdir, name) From 64942b02ca77c373873897c77db3d6e88f75efb1 Mon Sep 17 00:00:00 2001 From: oittaa <8972248+oittaa@users.noreply.github.com> Date: Mon, 31 Jan 2022 08:42:04 +0100 Subject: [PATCH 2/2] gcloud_helpers isn't needed anymore --- django_gcloud_storage/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django_gcloud_storage/__init__.py b/django_gcloud_storage/__init__.py index 6a42934..2bfc7f9 100644 --- a/django_gcloud_storage/__init__.py +++ b/django_gcloud_storage/__init__.py @@ -15,7 +15,6 @@ from django.core.files.storage import Storage from django.utils.deconstruct import deconstructible from django.utils.encoding import force_str, smart_str -from google.cloud import _helpers as gcloud_helpers from google.cloud import storage from google.cloud.exceptions import NotFound from google.cloud.storage.bucket import Bucket