From 5238b4297bb1858d9dde53e17807a7f336419405 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 13 Feb 2017 14:57:38 -0500 Subject: [PATCH] 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. --- bigquery/google/cloud/bigquery/query.py | 2 +- bigquery/unit_tests/test_query.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bigquery/google/cloud/bigquery/query.py b/bigquery/google/cloud/bigquery/query.py index 95d2eabdbdbe..7eb47b141191 100644 --- a/bigquery/google/cloud/bigquery/query.py +++ b/bigquery/google/cloud/bigquery/query.py @@ -351,7 +351,7 @@ def run(self, client=None): :param client: the client to use. If not passed, falls back to the ``client`` stored on the current dataset. """ - if self._job is not None: + if self.job is not None: raise ValueError("Query job is already running.") client = self._require_client(client) diff --git a/bigquery/unit_tests/test_query.py b/bigquery/unit_tests/test_query.py index 0e388c3cd0d9..096aa93ca35b 100644 --- a/bigquery/unit_tests/test_query.py +++ b/bigquery/unit_tests/test_query.py @@ -274,6 +274,15 @@ def test_run_w_already_has_job(self): with self.assertRaises(ValueError): query.run() + def test_run_w_already_has_job_in_properties(self): + JOB_ID = 'JOB_ID' + conn = _Connection() + client = _Client(project=self.PROJECT, connection=conn) + query = self._make_one(self.QUERY, client) + query._properties['jobReference'] = {'jobId': JOB_ID} + with self.assertRaises(ValueError): + query.run() + def test_run_w_bound_client(self): PATH = 'projects/%s/queries' % self.PROJECT RESOURCE = self._makeResource(complete=False)