Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

feat: add support for Etag headers on reads - #489

Merged
gcf-merge-on-green[bot] merged 17 commits into
googleapis:masterfrom
daniellehanks:etag-headers
Jul 8, 2021
Merged

feat: add support for Etag headers on reads#489
gcf-merge-on-green[bot] merged 17 commits into
googleapis:masterfrom
daniellehanks:etag-headers

Conversation

@daniellehanks

@daniellehanksdaniellehanks commented Jul 6, 2021

Copy link
Copy Markdown
Contributor

Support conditional requests based on ETag for read operations (reload, exists, download_*). My own testing seems to indicate that the JSON API does not support ETag If-Match/If-None-Match headers on modify requests (patch, delete, etc.), please correct me if I am mistaken.

This part two of #451. Part one in #488.
Fixes#451 🦕

@product-auto-labelproduct-auto-labelBot added the api: storage Issues related to the googleapis/python-storage API. label Jul 6, 2021
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Jul 6, 2021
Comment threadgoogle/cloud/storage/_helpers.py
@daniellehanksdaniellehanks mentioned this pull request Jul 6, 2021
@tseavertseaver changed the title Etag headers on readsfeat: add support for Etag headers on readsJul 6, 2021

@tseavertseaver left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the patch!

Comment threadgoogle/cloud/storage/_helpers.py
Comment threaddocs/generation_metageneration.rst Outdated
Comment threadgoogle/cloud/storage/_helpers.py Outdated
Comment threadgoogle/cloud/storage/blob.py Outdated
Comment threadgoogle/cloud/storage/bucket.py Outdated
Comment threadtests/unit/test__helpers.py Outdated
Comment threadtests/unit/test_blob.py Outdated
Comment threadtests/unit/test_client.py Outdated
@tseavertseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 6, 2021
@yoshi-kokoroyoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 6, 2021
@daniellehanks

Copy link
Copy Markdown
ContributorAuthor

Thanks very much for the patch!

Appreciate the preview review so I can address requested changes before writing system tests.

@daniellehanks

Copy link
Copy Markdown
ContributorAuthor

PR feedback addressed. Still need to add system tests. Hoping to find some time tonight.

Comment threadgoogle/cloud/storage/_helpers.py
if value is not None:
if isinstance(value, str):
value = [value]
headers[header_name] = ", ".join(value)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me (though I'm not a spec expert) that the GCS API isn't following spec putting quotes around the etag values. E.g. If-None-Match: COKaz4vVzfECEAE= works as intended but If-None-Match: "COKaz4vVzfECEAE=" does not. That said, the response header is also not quoted as it apparently should be etag: COKaz4vVzfECEAE= vs expected etag: "COKaz4vVzfECEAE=". Referencing this and this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe its just the display layers or something (using Chrome dev tools and curl). Wikipedia does the same thing.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

microsoft.com has it quoted 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC 7232 is the actual authoritative spec for conditional HTTP requests: If-Match and If-None-Match. The Collected ABNF appendix does indeed seem to require the double quote.

The GCS docs for the ETag header show the quotes as well.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, all the examples in the spec are also quoted. Fun times. Definitely out of scope for this PR. Just wanted to call it out. I would think the etag itself should have the quotes (i.e. blob.etag = '"Csdlei="'), so then this code would still function correctly. Of course getting etags quoted would be a far larger change spanning the backend, possibly ESF, and probably a fair amount of Hyrum's law.

It just stood out to me because I ran into a similar problem implementing the UI for BigQuery, which also doesn't follow the etag spec. In the end it meant we couldn't cache tables in the UI. But we also couldn't change the API without risking breaking clients. I'll leave it up to you if you want to file an internal ticket for that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectively we're stuck with the as-implemented back-end. @frankyn, @andrewsg, @tswast I'll leave it to y'all to open a ticket on the back-end (if one isn't there already) for the out-of-spec behavior.

@daniellehanks

Copy link
Copy Markdown
ContributorAuthor

I added two system tests. The first for the client as requested. The second for blob crud modeled after generation crud (but without write operations). There wasn't an existing system test for bucket metageneration stuff, so I didn't add one there for etags. Please let me know if there are any other tests you would like to see added.

I'm removing draft status as this PR is now complete from my perspective.

@daniellehanks
daniellehanks marked this pull request as ready for review July 7, 2021 05:59
@daniellehanks
daniellehanks requested review from a team and tseaverJuly 7, 2021 05:59
@daniellehanks

Copy link
Copy Markdown
ContributorAuthor

FYI I ran the system tests for 2.7 and caught a bug in the etag helper (instance check for str doesn't work for unicode type in 2.7) that the unit tests didn't catch (because they don't round trip the etag). Fixed by using six.string_types.

@tseavertseaver added automerge Merge the pull request once unit tests and other checks pass. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 8, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 8, 2021
@tseavertseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 8, 2021
@google-cla

google-claBot commented Jul 8, 2021

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-clagoogle-claBot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jul 8, 2021
@tseaver

Copy link
Copy Markdown
Contributor

@googlebot I consent.

@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 8, 2021
@google-clagoogle-claBot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Jul 8, 2021
Comment threadtests/system/test_client.py Outdated
Comment threadtests/unit/test_client.py Outdated
@tseavertseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 8, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 8, 2021
@gcf-merge-on-green
gcf-merge-on-greenBot merged commit 741d3fd into googleapis:masterJul 8, 2021
@gcf-merge-on-greengcf-merge-on-greenBot removed the automerge Merge the pull request once unit tests and other checks pass. label Jul 8, 2021
@tseaver

Copy link
Copy Markdown
Contributor

Thanks, again, @daniellehanks for your effort!

cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Support conditional requests based on ETag for read operations (`reload`, `exists`, `download_*`). My own testing seems to indicate that the JSON API does not support ETag If-Match/If-None-Match headers on modify requests (`patch`, `delete`, etc.), please correct me if I am mistaken.
This part two of googleapis#451. Part one in googleapis#488.
Fixesgoogleapis#451 🦕
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Support conditional requests based on ETag for read operations (`reload`, `exists`, `download_*`). My own testing seems to indicate that the JSON API does not support ETag If-Match/If-None-Match headers on modify requests (`patch`, `delete`, etc.), please correct me if I am mistaken.
This part two of googleapis#451. Part one in googleapis#488.
Fixesgoogleapis#451 🦕
@release-pleaserelease-pleaseBot mentioned this pull request Jan 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storageIssues related to the googleapis/python-storage API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ETag headers

3 participants

@daniellehanks@tseaver@yoshi-kokoro