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: handle case when expirationMs is None #1553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,11 @@ def partition_expiration(self, value):

if self.time_partitioning is None:
self._properties[api_field] = {"type": TimePartitioningType.DAY}
self._properties[api_field]["expirationMs"] = str(value)

if value is None:
self._properties[api_field]["expirationMs"] = None
else:
self._properties[api_field]["expirationMs"] = str(value)

@property
def clustering_fields(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,25 @@ def test_to_api_repr_w_custom_field(self):
}
self.assertEqual(resource, exp_resource)

def test_to_api_repr_w_unsetting_expiration(self):
from google.cloud.bigquery.table import TimePartitioningType

dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref)
table.partition_expiration = None
resource = table.to_api_repr()

exp_resource = {
"tableReference": table_ref.to_api_repr(),
"labels": {},
"timePartitioning": {
"expirationMs": None,
"type": TimePartitioningType.DAY,
},
}
self.assertEqual(resource, exp_resource)

def test__build_resource_w_custom_field(self):
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
Expand Down