Skip to content

Commit fa6e13d

Browse files
abdelmegahedtswast
andauthored
fix: handle case when expirationMs is None (#1553)
* hotfix: handle case when expirationMs is None * Add test for unsetting table exp * Update tests/unit/test_table.py * Update exp_resource for the unsetting_exp test --------- Co-authored-by: Tim Swast <[email protected]>
1 parent 075aa66 commit fa6e13d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

google/cloud/bigquery/table.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,11 @@ def partition_expiration(self, value):
687687

688688
if self.time_partitioning is None:
689689
self._properties[api_field] = {"type": TimePartitioningType.DAY}
690-
self._properties[api_field]["expirationMs"] = str(value)
690+
691+
if value is None:
692+
self._properties[api_field]["expirationMs"] = None
693+
else:
694+
self._properties[api_field]["expirationMs"] = str(value)
691695

692696
@property
693697
def clustering_fields(self):

tests/unit/test_table.py

+19
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,25 @@ def test_to_api_repr_w_custom_field(self):
11901190
}
11911191
self.assertEqual(resource, exp_resource)
11921192

1193+
def test_to_api_repr_w_unsetting_expiration(self):
1194+
from google.cloud.bigquery.table import TimePartitioningType
1195+
1196+
dataset = DatasetReference(self.PROJECT, self.DS_ID)
1197+
table_ref = dataset.table(self.TABLE_NAME)
1198+
table = self._make_one(table_ref)
1199+
table.partition_expiration = None
1200+
resource = table.to_api_repr()
1201+
1202+
exp_resource = {
1203+
"tableReference": table_ref.to_api_repr(),
1204+
"labels": {},
1205+
"timePartitioning": {
1206+
"expirationMs": None,
1207+
"type": TimePartitioningType.DAY,
1208+
},
1209+
}
1210+
self.assertEqual(resource, exp_resource)
1211+
11931212
def test__build_resource_w_custom_field(self):
11941213
dataset = DatasetReference(self.PROJECT, self.DS_ID)
11951214
table_ref = dataset.table(self.TABLE_NAME)

0 commit comments

Comments
 (0)