Skip to content

Storage: assigning 'Bucket.retention_policy' to None fails in systests #6368

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

Closed
tseaver opened this issue Nov 1, 2018 · 4 comments
Closed
Assignees
Labels
api: storage Issues related to the Cloud Storage API. backend priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tseaver
Copy link
Contributor

tseaver commented Nov 1, 2018

See the non-flaky-looking failures today:

__________ TestRetentionPolicy.test_bucket_w_retention_period ______________

 = <tests.system.TestRetentionPolicy testMethod=test_bucket_w_retention_period>

def test_bucket_w_retention_period(self):
    import datetime
    from google.api_core import exceptions

    period_secs = 10

    new_bucket_name = 'w-retention-period' + unique_resource_id('-')
    bucket = Config.CLIENT.create_bucket(new_bucket_name)
    self.case_buckets_to_delete.append(new_bucket_name)

    bucket.retention_period = period_secs
    bucket.default_event_based_hold = False
    bucket.patch()

    self.assertEqual(bucket.retention_period, period_secs)
    self.assertIsInstance(
        bucket.retention_policy_effective_time, datetime.datetime)
    self.assertFalse(bucket.default_event_based_hold)
    self.assertFalse(bucket.retention_policy_locked)

    blob_name = 'test-blob'
    payload = b'DEADBEEF'
    blob = bucket.blob(blob_name)
    blob.upload_from_string(payload)

    other = bucket.get_blob(blob_name)

    self.assertFalse(other.event_based_hold)
    self.assertFalse(other.temporary_hold)
    self.assertIsInstance(
        other.retention_expiration_time, datetime.datetime)

    with self.assertRaises(exceptions.Forbidden):
        other.delete()

    bucket.retention_period = None
    bucket.patch()
...

        BadRequest: 400 PATCH https://www.googleapis.com/storage/v1/b/w-retention-period-1541108415593?projection=full: Retention policy must have a retention period greater than 0 and less than 100 years.

@frankyn Has something changed on the back-end about this case? These tests have been passing.

@tseaver tseaver added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: storage Issues related to the Cloud Storage API. backend priority: p2 Moderately-important priority. Fix may not be included in next release. labels Nov 1, 2018
@frankyn
Copy link
Contributor

frankyn commented Nov 2, 2018

This is strange, I'm researching, from a brief inspection it is as if it no longer accepts the None value in Python.

@frankyn
Copy link
Contributor

frankyn commented Nov 2, 2018

I think it changed based on it no longer accepts None when a Retention policy is defined. It used to accept it. I will follow-up on such subtle changes in the backend.

As for the fix, I missed this during the review, because I have learned more!
From https://github.com/googleapis/google-cloud-python/blob/master/storage/google/cloud/storage/bucket.py#L1348-L1352
Change to:

    @retention_period.setter
    def retention_period(self, value):
        """Set the retention period for items in the bucket.
        :type value: int
        :param value:
            number of seconds to retain items after upload or release from
            event-based lock.
        :raises ValueError: if the bucket's retention policy is locked.
        """
        policy = self._properties.setdefault('retentionPolicy', {})
        if value is not None:
            policy['retentionPeriod'] = str(value)
        else:
            policy = None
        self._patch_property('retentionPolicy', policy)

@frankyn
Copy link
Contributor

frankyn commented Nov 2, 2018

Internal tracking bug: 115765214

@frankyn
Copy link
Contributor

frankyn commented Nov 5, 2018

Short update: turns out it was a bug in the feature that has since been fixed. The client shouldn't have depended on this route in the first place. I missed this during the review.

Thanks @tseaver for the fast fix!

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 Cloud Storage API. backend priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants