Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revise and rename is_etag_in_json(data) #483

Merged
merged 10 commits into from Jul 9, 2021
Merged

fix: revise and rename is_etag_in_json(data) #483

merged 10 commits into from Jul 9, 2021

Conversation

cojenco
Copy link
Contributor

@cojenco cojenco commented Jun 28, 2021

This PR revises and renames retry.is_etag_in_json(data) to ensure that eTags are correctly captured and validated from the request body.

  • Rename conditional retry predicate retry.is_etag_in_json(data) to retry.is_etag_in_data(data). It returns a boolean whether or not an etag is contained in the request body.
  • Revise retry.is_etag_in_data(data) to reflect library use cases in which data is dict or None
  • Update tests and docs

Fixes #481 馃

@cojenco cojenco requested a review from a team June 28, 2021 19:32
@cojenco cojenco requested a review from a team as a code owner June 28, 2021 19:32
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Jun 28, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 28, 2021
@cojenco cojenco requested a review from tseaver July 9, 2021 16:54
Copy link
Contributor

@tritone tritone left a 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!

pass
return False
:type data: dict or None
:param data: A dict containing the JSON body. If not passed, returns False.
Copy link
Contributor

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@cojenco cojenco changed the title fix: handle cases where data is a dict in is_etag_in_json(data) fix: revise and rename is_etag_in_json(data) Jul 9, 2021
@cojenco cojenco merged commit 0a52546 into master Jul 9, 2021
@cojenco cojenco deleted the etag_in_json branch July 9, 2021 22:21
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
* 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
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle data dict type in retry.is_etag_in_json(data)
3 participants