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: Do not set job timeout extra property if None #1987

Merged
merged 2 commits into from
Aug 19, 2024
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
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:
bmwant marked this conversation as resolved.
Show resolved Hide resolved
# 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