Skip to content

Commit fcd6336

Browse files
authored
test: look for transaction info on child job, not parent job (#978)
* test: look for transaction info on child job, not parent job * clarify transaction_info docstring * use sphinx method directive
1 parent 1cef0d4 commit fcd6336

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

google/cloud/bigquery/job/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ def reservation_usage(self):
357357
def transaction_info(self) -> Optional[TransactionInfo]:
358358
"""Information of the multi-statement transaction if this job is part of one.
359359
360+
Since a scripting query job can execute multiple transactions, this
361+
property is only expected on child jobs. Use the
362+
:meth:`google.cloud.bigquery.client.Client.list_jobs` method with the
363+
``parent_job`` parameter to iterate over child jobs.
364+
360365
.. versionadded:: 2.24.0
361366
"""
362367
info = self._properties.get("statistics", {}).get("transactionInfo")

tests/system/test_client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,9 +1586,15 @@ def test_transaction_info(self):
15861586
query_job = Config.CLIENT.query(sql)
15871587
query_job.result()
15881588

1589-
# Transaction ID set by the server should be accessible
1590-
assert query_job.transaction_info is not None
1591-
assert query_job.transaction_info.transaction_id != ""
1589+
child_jobs = Config.CLIENT.list_jobs(parent_job=query_job)
1590+
begin_transaction_job = next(iter(child_jobs))
1591+
1592+
# Transaction ID set by the server should be accessible on the child
1593+
# job responsible for `BEGIN TRANSACTION`. It is not expected to be
1594+
# present on the parent job itself.
1595+
# https://github.com/googleapis/python-bigquery/issues/975
1596+
assert begin_transaction_job.transaction_info is not None
1597+
assert begin_transaction_job.transaction_info.transaction_id != ""
15921598

15931599
def test_dbapi_w_standard_sql_types(self):
15941600
for sql, expected in helpers.STANDARD_SQL_EXAMPLES:

0 commit comments

Comments
 (0)