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 Jun 28, 2021
@cojenco cojenco requested a review from as a code owner Jun 28, 2021
@google-cla google-cla bot added the cla: yes label Jun 28, 2021
google/cloud/storage/retry.py Outdated Show resolved Hide resolved
@cojenco cojenco requested a review from tseaver Jul 9, 2021
tritone
tritone approved these changes Jul 9, 2021
Copy link
Contributor

@tritone tritone left a comment

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

@tritone tritone Jul 9, 2021

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

@tseaver tseaver Jul 9, 2021

We could rename it and leave is_etag_in_json around as a backward-compatibility alias.

Copy link
Contributor Author

@cojenco cojenco Jul 9, 2021

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

@tseaver tseaver Jul 9, 2021

LGTM

google/cloud/storage/retry.py Outdated Show resolved Hide resolved
tritone
tritone approved these changes Jul 9, 2021
@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
6 checks passed
@cojenco cojenco deleted the etag_in_json branch Jul 9, 2021
cojenco added a commit to cojenco/python-storage that referenced this issue 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 issue 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants