Skip to content

Commit

Permalink
fix: do not set job timeout extra property if None
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwant committed Aug 18, 2024
1 parent 8f5a41d commit 166ca14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions google/cloud/bigquery/job/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ def job_timeout_ms(self, value):
err.__traceback__
)

""" Docs indicate a string is expected by the API """
self._properties["jobTimeoutMs"] = str(value)
if value is not None:
# docs indicate a string is expected by the API
self._properties["jobTimeoutMs"] = str(value)
else:
self._properties.pop("jobTimeoutMs", None)

@property
def labels(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/job/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,21 @@ def test_job_timeout_ms(self):
# Confirm that integers get converted to strings.
job_config.job_timeout_ms = 5000
assert job_config.job_timeout_ms == "5000" # int is converted to string

def test_job_timeout_is_none_when_set_none(self):
job_config = self._make_one()
job_config.job_timeout_ms = None
# Confirm value is None and not literal string 'None'
assert job_config.job_timeout_ms is None

def test_job_timeout_properties(self):
# Make sure any value stored in properties is erased
# when setting job_timeout to None.
job_config = self._make_one()
job_config.job_timeout_ms = 4200
assert job_config.job_timeout_ms == "4200"
assert job_config._properties.get("jobTimeoutMs") == "4200"

job_config.job_timeout_ms = None
assert job_config.job_timeout_ms is None
assert "jobTimeoutMs" not in job_config._properties

0 comments on commit 166ca14

Please sign in to comment.