From 514d3e12e5131bd589dff08893fd89bf40338ba3 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Mon, 2 Oct 2023 11:56:44 -0500 Subject: [PATCH] fix: allow `storage_billing_model` to be explicitly set to `None` to use project default value (#1665) * fix: allow `storage_billing_model` to be explicitly set to `None` to use project default value * add STORAGE_BILLING_MODEL_UNSPECIFIED to docstring --- google/cloud/bigquery/dataset.py | 17 ++++++++--------- tests/unit/test_dataset.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/google/cloud/bigquery/dataset.py b/google/cloud/bigquery/dataset.py index 114f0de18..a9c1cd884 100644 --- a/google/cloud/bigquery/dataset.py +++ b/google/cloud/bigquery/dataset.py @@ -769,9 +769,10 @@ def storage_billing_model(self): """Union[str, None]: StorageBillingModel of the dataset as set by the user (defaults to :data:`None`). - Set the value to one of ``'LOGICAL'`` or ``'PHYSICAL'``. This change - takes 24 hours to take effect and you must wait 14 days before you can - change the storage billing model again. + Set the value to one of ``'LOGICAL'``, ``'PHYSICAL'``, or + ``'STORAGE_BILLING_MODEL_UNSPECIFIED'``. This change takes 24 hours to + take effect and you must wait 14 days before you can change the storage + billing model again. See `storage billing model `_ @@ -788,13 +789,11 @@ def storage_billing_model(self): def storage_billing_model(self, value): if not isinstance(value, str) and value is not None: raise ValueError( - "storage_billing_model must be a string (e.g. 'LOGICAL', 'PHYSICAL'), or None. " - f"Got {repr(value)}." + "storage_billing_model must be a string (e.g. 'LOGICAL'," + " 'PHYSICAL', 'STORAGE_BILLING_MODEL_UNSPECIFIED'), or None." + f" Got {repr(value)}." ) - if value: - self._properties["storageBillingModel"] = value - if value is None: - self._properties["storageBillingModel"] = "LOGICAL" + self._properties["storageBillingModel"] = value @classmethod def from_string(cls, full_dataset_id: str) -> "Dataset": diff --git a/tests/unit/test_dataset.py b/tests/unit/test_dataset.py index f2bdf8db5..3b1452805 100644 --- a/tests/unit/test_dataset.py +++ b/tests/unit/test_dataset.py @@ -955,7 +955,7 @@ def test_storage_billing_model_setter(self): def test_storage_billing_model_setter_with_none(self): dataset = self._make_one(self.DS_REF) dataset.storage_billing_model = None - self.assertEqual(dataset.storage_billing_model, "LOGICAL") + self.assertIsNone(dataset.storage_billing_model) def test_storage_billing_model_setter_with_invalid_type(self): dataset = self._make_one(self.DS_REF)