-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Making all Blob/Bucket getters fail gracefully if keys don't exist. #793
Making all Blob/Bucket getters fail gracefully if keys don't exist. #793
Conversation
@@ -38,7 +39,7 @@ def __init__(self, message, errors=()): | |||
super(GCloudError, self).__init__() | |||
# suppress deprecation warning under 2.6.x | |||
self.message = message | |||
self._errors = [error.copy() for error in errors] | |||
self._errors = errors |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ISTM that returning None from the getters breaks their contract a bit: we could either change the |
@tseaver I imagine a future where people use their own blob.reload(fields=['generation', 'metageneration']) and then all other values are unset. I think changing the |
Also - replacing uses of dict.copy() (shallow) with copy.deepcopy(). - Making getters honor contracts (e.g. return an integer if supposed to). This is necessary because int64 -> JSON becomes a string, even though we want an integer. This is due to only one numeric type "number" in JavaScript.
873ec53
to
2971484
Compare
@tseaver I updated the docstrings and pushed again. I also coerced some values to ints, since I also wanted to convert the timestamps to datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%fZ') would be insufficient for values returned by the backend (AFAIK the only contract is that they will be valid RFC3339). |
@@ -553,7 +583,8 @@ def metadata(self, value): | |||
|
|||
See: https://cloud.google.com/storage/docs/json_api/v1/objects | |||
|
|||
:type value: dict | |||
:type value: dict or ``NoneType`` | |||
:param value: The blob metadata to set. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Aside from the worry about PATCH w/ None, LGTM. |
PATCH with None effectively "unsets" the property. But we would only send None if it was explicitly set by the user. I'm AFK now but would like to test out what happens if None is sent for a required property. |
@tseaver What is the implication of my answer? How to move forward? |
We should figure out what happens when |
@tseaver I was already pretty sure what happened, but I verified via https://developers.google.com/apis-explorer/#p/storage/v1/storage.objects.patch by sending "metadata: null" after previously setting |
OK. ISTM we can just mirror that, then (the |
Yep, we get it for free. Remaining hangups? |
Nope. |
…orage Making all Blob/Bucket getters fail gracefully if keys don't exist.
Also replacing uses of dict.copy() (shallow) with copy.deepcopy().