-
Notifications
You must be signed in to change notification settings - Fork 154
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
fix: revise and rename is_etag_in_json(data) #483
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much cleaner, thank you!
google/cloud/storage/retry.py
Outdated
pass | ||
return False | ||
:type data: dict or None | ||
:param data: A dict containing the JSON body. If not passed, returns False. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we could be clearer that the dict represents the JSON body rather than containing it. Also, this is specifically intended for calls where metadata is sent in the request body.
It seems like it'd be better to actually just rename this function to is_etag_in_data
but I guess technically this is part of the public surface of the library (even if we don't expect external callers to use it directly)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could rename it and leave is_etag_in_json
around as a backward-compatibility alias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be something like this:
def is_etag_in_data(data):
"""Return True if an etag is contained in the request body.
:type data: dict or None
:param data: A dict representing the request JSON body. If not passed, returns False.
"""
return data is not None and "etag" in data
def is_etag_in_json(data):
"""
``is_etag_in_json`` is supported for backwards-compatibility reasons only;
please use ``is_etag_in_data`` instead.
"""
return is_etag_in_data(data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* fix: handle cases where data is a dict in is_etag_in_json(data) * address comments and accept proposed changes * revise is_etag_in_json to check dict data * revise docstring wording * revise docstrings * rename conditional predicate to is_etag_in_data
* fix: handle cases where data is a dict in is_etag_in_json(data) * address comments and accept proposed changes * revise is_etag_in_json to check dict data * revise docstring wording * revise docstrings * rename conditional predicate to is_etag_in_data
This PR revises and renames
retry.is_etag_in_json(data)
to ensure that eTags are correctly captured and validated from the request body.retry.is_etag_in_json(data)
toretry.is_etag_in_data(data)
. It returns a boolean whether or not anetag
is contained in the request body.retry.is_etag_in_data(data)
to reflect library use cases in whichdata
isdict
orNone
Fixes #481 🦕