[GH-ISSUE #299] Support for preconditions #2210

Open
opened 2026-03-15 18:02:36 +03:00 by kerem · 4 comments
Owner

Originally created by @charleskorn on GitHub (Aug 5, 2020).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/299

Does this server support preconditions? (https://cloud.google.com/storage/docs/generations-preconditions#_Preconditions)

I've tried adding the following to my upload code:

w := c.bucket.
	Object("myobject.json").
	If(cloudstorage.Conditions{DoesNotExist: true}).
	NewWriter(ctx)

But the server always overwrites the object, even if it exists, instead of returning a HTTP 412 response. I can see that the upload URL contains ifGenerationMatch=0 in the server's logs.

Originally created by @charleskorn on GitHub (Aug 5, 2020). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/299 Does this server support preconditions? (https://cloud.google.com/storage/docs/generations-preconditions#_Preconditions) I've tried adding the following to my upload code: ```go w := c.bucket. Object("myobject.json"). If(cloudstorage.Conditions{DoesNotExist: true}). NewWriter(ctx) ``` But the server always overwrites the object, even if it exists, instead of returning a HTTP 412 response. I can see that the upload URL contains `ifGenerationMatch=0` in the server's logs.
Author
Owner

@someone1 commented on GitHub (Aug 27, 2020):

Yikes, the v.1.20.0 release was a breaking one - all my tests started to fail. Glad to see some progress being made on this but maybe we can keep the original behavior of allowing the request through vs a 501 response?

<!-- gh-comment-id:681481814 --> @someone1 commented on GitHub (Aug 27, 2020): Yikes, the `v.1.20.0` release was a breaking one - all my tests started to fail. Glad to see some progress being made on this but maybe we can keep the original behavior of allowing the request through vs a 501 response?
Author
Owner

@someone1 commented on GitHub (Aug 27, 2020):

A quick follow-up: was the implementation in #300 the correct placement for such a feature? The generation feature seems backend dependent (e.g. the memory backend supports file generations whereas the file backend does not). Would it have made more sense to expand the Storage interface with a CreateObjectIfGenerationMatch or something to be used instead of CreateObject as needed, or expand CreateObject to take in a precondition struct to process? This way, each backend can properly implement the features it supports (with locking) vs the current approach.

Thoughts?

cc @fsouza

<!-- gh-comment-id:681528155 --> @someone1 commented on GitHub (Aug 27, 2020): A quick follow-up: was the implementation in #300 the correct placement for such a feature? The generation feature seems backend dependent (e.g. the memory backend supports file generations whereas the file backend does not). Would it have made more sense to expand the `Storage` interface with a `CreateObjectIfGenerationMatch` or something to be used instead of `CreateObject` as needed, or expand `CreateObject` to take in a precondition struct to process? This way, each backend can properly implement the features it supports (with locking) vs the current approach. Thoughts? cc @fsouza
Author
Owner

@fsouza commented on GitHub (Aug 27, 2020):

Ugh, sorry about that :(( We should expand our shared tests to cover more behaviors. I'll make sure to keep an eye for that in the future (most of my use cases are using the memory backend :/).

I feel like extending the backend's CreateObject method is the best approach here, the same way we extended CreateBucket to pass versioningEnabled.

<!-- gh-comment-id:681877735 --> @fsouza commented on GitHub (Aug 27, 2020): Ugh, sorry about that :(( We should expand our shared tests to cover more behaviors. I'll make sure to keep an eye for that in the future (most of my use cases are using the memory backend :/). I feel like extending the backend's CreateObject method is the best approach here, the same way we extended CreateBucket to pass versioningEnabled.
Author
Owner

@bmansoob commented on GitHub (Apr 27, 2022):

👋 @fsouza

I see generation support has been added in https://github.com/fsouza/fake-gcs-server/pull/735 at the same layer as in #300.

I added support for this in the memory backend here. I wanted to confirm with you first, before opening a pull request, that do you still plan on tackling this in a backend specific way.

<!-- gh-comment-id:1111578889 --> @bmansoob commented on GitHub (Apr 27, 2022): 👋 @fsouza I see generation support has been added in https://github.com/fsouza/fake-gcs-server/pull/735 at the same layer as in #300. I added support for this in the memory backend [here](https://github.com/fsouza/fake-gcs-server/compare/main...bmansoob:generation-match-support?expand=1). I wanted to confirm with you first, before opening a pull request, that do you still plan on tackling this in a backend specific way.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#2210
No description provided.