From 75f705b8ec1c2623677391d204f017c58c0e5346 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 21 Sep 2021 09:38:29 -0500 Subject: [PATCH 1/3] test: look for transaction info on child job, not parent job --- tests/system/test_client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/system/test_client.py b/tests/system/test_client.py index 9da45ee6e..6c8da4d23 100644 --- a/tests/system/test_client.py +++ b/tests/system/test_client.py @@ -1586,9 +1586,15 @@ def test_transaction_info(self): query_job = Config.CLIENT.query(sql) query_job.result() - # Transaction ID set by the server should be accessible - assert query_job.transaction_info is not None - assert query_job.transaction_info.transaction_id != "" + child_jobs = Config.CLIENT.list_jobs(parent_job=query_job) + begin_transaction_job = next(iter(child_jobs)) + + # Transaction ID set by the server should be accessible on the child + # job responsible for `BEGIN TRANSACTION`. It is not expected to be + # present on the parent job itself. + # https://github.com/googleapis/python-bigquery/issues/975 + assert begin_transaction_job.transaction_info is not None + assert begin_transaction_job.transaction_info.transaction_id != "" def test_dbapi_w_standard_sql_types(self): for sql, expected in helpers.STANDARD_SQL_EXAMPLES: From b1e64e9e1afb403cd602c578c4010b9692225d6a Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 21 Sep 2021 09:52:55 -0500 Subject: [PATCH 2/3] clarify transaction_info docstring --- google/cloud/bigquery/job/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/google/cloud/bigquery/job/base.py b/google/cloud/bigquery/job/base.py index 72db5a63c..988d513b2 100644 --- a/google/cloud/bigquery/job/base.py +++ b/google/cloud/bigquery/job/base.py @@ -357,6 +357,11 @@ def reservation_usage(self): def transaction_info(self) -> Optional[TransactionInfo]: """Information of the multi-statement transaction if this job is part of one. + Since a scripting query job can execute multiple transactions, this + property is only expected on child jobs. Use the + :func:`google.cloud.bigquery.client.Client.list_jobs` method with the + ``parent_job`` parameter to iterate over child jobs. + .. versionadded:: 2.24.0 """ info = self._properties.get("statistics", {}).get("transactionInfo") From 536342aea9392d27ee530b56f1f13e4cc4cfdd0a Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 21 Sep 2021 10:08:41 -0500 Subject: [PATCH 3/3] use sphinx method directive --- google/cloud/bigquery/job/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/cloud/bigquery/job/base.py b/google/cloud/bigquery/job/base.py index 988d513b2..698181092 100644 --- a/google/cloud/bigquery/job/base.py +++ b/google/cloud/bigquery/job/base.py @@ -359,7 +359,7 @@ def transaction_info(self) -> Optional[TransactionInfo]: Since a scripting query job can execute multiple transactions, this property is only expected on child jobs. Use the - :func:`google.cloud.bigquery.client.Client.list_jobs` method with the + :meth:`google.cloud.bigquery.client.Client.list_jobs` method with the ``parent_job`` parameter to iterate over child jobs. .. versionadded:: 2.24.0