Skip to content

test: look for transaction info on child job, not parent job #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/cloud/bigquery/job/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 9 additions & 3 deletions tests/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down