Skip to content

Commit 5238b42

Browse files
committed
Check running status via 'job' property.
If the '_job' attribute is not set, but we have a 'jobId' in our properties, we still don't want to re-run the query. Closes #3003.
1 parent 9619004 commit 5238b42

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

bigquery/google/cloud/bigquery/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def run(self, client=None):
351351
:param client: the client to use. If not passed, falls back to the
352352
``client`` stored on the current dataset.
353353
"""
354-
if self._job is not None:
354+
if self.job is not None:
355355
raise ValueError("Query job is already running.")
356356

357357
client = self._require_client(client)

bigquery/unit_tests/test_query.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ def test_run_w_already_has_job(self):
274274
with self.assertRaises(ValueError):
275275
query.run()
276276

277+
def test_run_w_already_has_job_in_properties(self):
278+
JOB_ID = 'JOB_ID'
279+
conn = _Connection()
280+
client = _Client(project=self.PROJECT, connection=conn)
281+
query = self._make_one(self.QUERY, client)
282+
query._properties['jobReference'] = {'jobId': JOB_ID}
283+
with self.assertRaises(ValueError):
284+
query.run()
285+
277286
def test_run_w_bound_client(self):
278287
PATH = 'projects/%s/queries' % self.PROJECT
279288
RESOURCE = self._makeResource(complete=False)

0 commit comments

Comments
 (0)