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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from May 8, 2021

Conversation

cojenco
Copy link
Contributor

@cojenco cojenco commented May 7, 2021

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-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label May 7, 2021
@google-cla google-cla bot 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 a review from a team May 7, 2021 22:47
@cojenco cojenco requested a review from a team as a code owner May 7, 2021 22:47
Copy link
Contributor

@andrewsg andrewsg left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -2361,7 +2361,9 @@ def lifecycle_rules(self):
elif action_type == "SetStorageClass":
yield LifecycleRuleSetStorageClass.from_api_repr(rule)
else:
raise ValueError("Unknown lifecycle rule: {}".format(rule))
warnings.warn(
Copy link
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
Contributor Author

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
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
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
Contributor Author

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!

@cojenco cojenco added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 7, 2021
@@ -2361,7 +2361,13 @@ def lifecycle_rules(self):
elif action_type == "SetStorageClass":
yield LifecycleRuleSetStorageClass.from_api_repr(rule)
else:
raise ValueError("Unknown lifecycle rule: {}".format(rule))
warnings.warn(
"Unknown lifecycle rule by the client: {}. Please upgrade your client.".format(
Copy link
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
Contributor Author

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!

@cojenco cojenco 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-kokoro yoshi-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 master May 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
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.

None yet

4 participants