Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

fix: replace python lifecycle action parsing ValueError with warning - #437

Merged
cojenco merged 4 commits into
masterfrom
lifecycle-009
May 8, 2021
Merged

fix: replace python lifecycle action parsing ValueError with warning#437
cojenco merged 4 commits into
masterfrom
lifecycle-009

Conversation

@cojenco

Copy link
Copy Markdown
Contributor

Replace python Lifecycle action parsing ValueError with a user warning in cases where the client attempts to parse unexpected fields. This will help future proof this feature by preventing runtime errors for parsing unsupported actions.

@product-auto-labelproduct-auto-labelBot added the api: storage Issues related to the googleapis/python-storage API. label May 7, 2021
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label May 7, 2021
@cojenco
cojenco marked this pull request as ready for review May 7, 2021 22:47
@cojenco
cojenco requested review from a teamMay 7, 2021 22:47

@andrewsgandrewsg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

yield LifecycleRuleSetStorageClass.from_api_repr(rule)
else:
raise ValueError("Unknown lifecycle rule: {}".format(rule))
warnings.warn(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it cause issues if nothing is yielded here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Let me double check on that, thanks! Any insight on this @andrewsg?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I considered that in my review but decided it looked to me like because it's in a for loop, yielding nothing will behave identically to no rule at all, which is probably acceptable in this case. I'm not familiar with how people use this feature, however.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gotcha, I guess it will just continue to the next rule in the list and/or end the generator if nothing is left.

I was discussing this issue with someone who pointed me to this code in the Java Bigtable client: https://github.com/googleapis/java-bigtable/blob/master/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/EncryptionInfo.java#L48 . I like the message there-- could we also have the warning suggest upgrading to a newer client version?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

To the point of future proof, I think suggesting upgrading to a newer client version would make sense. Will incorporate that in!

@cojencocojenco added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 7, 2021
Comment threadgoogle/cloud/storage/bucket.py Outdated
else:
raise ValueError("Unknown lifecycle rule: {}".format(rule))
warnings.warn(
"Unknown lifecycle rule by the client: {}. Please upgrade your client.".format(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say something like Unknown lifecycle rule type received: {}. Please upgrade to the latest version of google-cloud-storage.

How does that sound?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

That sounds much better. Thanks for the review!

@cojencocojenco added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels May 8, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 8, 2021
@cojenco
cojenco merged commit 2532d50 into masterMay 8, 2021
@cojenco
cojenco deleted the lifecycle-009 branch May 8, 2021 07:58
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
…oogleapis#437)
* fix: replace python lifecycle action parsing ValueError with warning
* fix lint
* add client upgrade suggestion to unknown OLM rule warning
* update warning message
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
…oogleapis#437)
* fix: replace python lifecycle action parsing ValueError with warning
* fix lint
* add client upgrade suggestion to unknown OLM rule warning
* update warning message
@release-pleaserelease-pleaseBot mentioned this pull request Jan 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storageIssues related to the googleapis/python-storage API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@cojenco@andrewsg@tritone@yoshi-kokoro