diff --git a/google/cloud/bigquery/job/base.py b/google/cloud/bigquery/job/base.py index 72db5a63c..698181092 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 + :meth:`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") 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: