Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting blob.custom_time doesn't work, returns always None #410

Closed
oittaa opened this issue Feb 4, 2021 · 7 comments · Fixed by #1036
Closed

Setting blob.custom_time doesn't work, returns always None #410

oittaa opened this issue Feb 4, 2021 · 7 comments · Fixed by #1036

Comments

@oittaa
Copy link

oittaa commented Feb 4, 2021

I have a piece of code like the following:

self.client = storage.Client()
self.bucket = self.client.get_bucket(bucket_name)

blob = self.bucket.blob(blob_name)
blob.upload_from_string(value, content_type=content_type)
blob.reload()
blob.custom_time = datetime.datetime.now(datetime.timezone.utc)
blob.patch()

If I set custom_time before uploading, even the real Google server erases it from the blob. That's why I patch it after the upload. The fake server unfortunately loses it even after patch.

blob = self.bucket.get_blob(blob_name)
print(blob.custom_time)

results in None

@oittaa
Copy link
Author

oittaa commented Feb 5, 2021

To me it looks like the Custom-Time is completely missing from objects.

// Object represents the object that is stored within the fake server.
type Object struct {
BucketName string `json:"-"`
Name string `json:"name"`
ContentType string `json:"contentType"`
ContentEncoding string `json:"contentEncoding"`
Content []byte `json:"-"`
// Crc32c checksum of Content. calculated by server when it's upload methods are used.
Crc32c string `json:"crc32c,omitempty"`
Md5Hash string `json:"md5Hash,omitempty"`
ACL []storage.ACLRule `json:"acl,omitempty"`
// Dates and generation can be manually injected, so you can do assertions on them,
// or let us fill these fields for you
Created time.Time `json:"created,omitempty"`
Updated time.Time `json:"updated,omitempty"`
Deleted time.Time `json:"deleted,omitempty"`
Generation int64 `json:"generation,omitempty,string"`
Metadata map[string]string `json:"metadata,omitempty"`
}

https://cloud.google.com/storage/docs/metadata#custom-time
https://pkg.go.dev/cloud.google.com/go/storage#ObjectAttrsToUpdate

@oittaa
Copy link
Author

oittaa commented Feb 6, 2021

The original Google Cloud issue about missing custom_time before patching is tracked here. googleapis/python-storage#372

@fsouza
Copy link
Owner

fsouza commented Feb 15, 2021

Thanks for reporting and linking the docs!

@mar-pan
Copy link

mar-pan commented Dec 23, 2022

Hello @fsouza is there any chance that this could be assigned to someone and resolved? It looks like that Google resolved issue on their side and I can confirm that it works with "real" API

@fsouza
Copy link
Owner

fsouza commented Dec 28, 2022

I opened #1024 (big round-number!) as a draft, in case someone wants to work on it. It's unlikely I'll be able to pick it back up in the next couple of weeks.

@RachitSharma2001
Copy link
Contributor

@fsouza I believe I have a solution that fixes this issue and updates CustomTime correctly. I am ready to submit a pr but since my solution is based off the changes I made to this PR (specifically the changes added to PatchObject method in object.go) I just want to make sure that those changes are good before submitting a pr to fix this issue.

@fsouza
Copy link
Owner

fsouza commented Jan 7, 2023

@RachitSharma2001 hey, I'm going to look at your PR later today (in 2 hours or so). If you prefer, you can open another PR on top of that one, or we can wait.

Apologies for the delayed review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants