Update file_handlers.py get_requester_pays #153
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
get_requester_pays() is incorrectly returning False for buckets that are requester-pays. I copied this code block from canine into my notebook for testing:
canine/canine/localization/file_handlers.py
Lines 108 to 132 in 0cebe19
Here we see
bucket._properties
is empty, which is why this returns false.Solutions
Google's API suggests a different approach: https://cloud.google.com/storage/docs/using-requester-pays#storage-get-requester-pays-status-python
bucket.reload()
is used in google's own API above: https://github.com/googleapis/python-storage/blob/e3cfc4786209c77e3c879c9ff2978f4884a0d677/google/cloud/storage/client.py#L870-L877When I add
bucket.reload()
, we get the expected behavior (with the_properties
attribute filled):Alternatively, we use Google's recommended approach directly: