Skip to content
Permalink
Browse files
fix: replace python lifecycle action parsing ValueError with warning (#…
…437)

* fix: replace python lifecycle action parsing ValueError with warning

* fix lint

* add client upgrade suggestion to unknown OLM rule warning

* update warning message
  • Loading branch information
cojenco committed May 8, 2021
1 parent 246a13b commit 2532d506b44fc1ef0fa0a996822d29e7459c465a
Showing with 17 additions and 4 deletions.
  1. +7 −1 google/cloud/storage/bucket.py
  2. +10 −3 tests/unit/test_bucket.py
@@ -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 type received: {}. Please upgrade to the latest version of google-cloud-storage.".format(
rule
),
UserWarning,
stacklevel=1,
)

@lifecycle_rules.setter
def lifecycle_rules(self, rules):
@@ -1783,15 +1783,22 @@ def test_iam_configuration_policy_w_entry(self):
self.assertTrue(config.uniform_bucket_level_access_enabled)
self.assertEqual(config.uniform_bucket_level_access_locked_time, now)

def test_lifecycle_rules_getter_unknown_action_type(self):
@mock.patch("warnings.warn")
def test_lifecycle_rules_getter_unknown_action_type(self, mock_warn):
NAME = "name"
BOGUS_RULE = {"action": {"type": "Bogus"}, "condition": {"age": 42}}
rules = [BOGUS_RULE]
properties = {"lifecycle": {"rule": rules}}
bucket = self._make_one(name=NAME, properties=properties)

with self.assertRaises(ValueError):
list(bucket.lifecycle_rules)
list(bucket.lifecycle_rules)
mock_warn.assert_called_with(
"Unknown lifecycle rule type received: {}. Please upgrade to the latest version of google-cloud-storage.".format(
BOGUS_RULE
),
UserWarning,
stacklevel=1,
)

def test_lifecycle_rules_getter(self):
from google.cloud.storage.bucket import (

0 comments on commit 2532d50

Please sign in to comment.