Skip to content

docs: fix markdown formatting in transactions page #1377

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 2 commits into from
May 20, 2025
Merged
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
32 changes: 19 additions & 13 deletions docs/transaction-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ A :class:`~google.cloud.spanner_v1.transaction.Transaction` represents a
transaction: when the transaction commits, it will send any accumulated
mutations to the server.

To understand more about how transactions work, visit [Transaction](https://cloud.google.com/spanner/docs/reference/rest/v1/Transaction).
To understand more about how transactions work, visit
`Transaction <https://cloud.google.com/spanner/docs/reference/rest/v1/Transaction>`_.
To learn more about how to use them in the Python client, continue reading.


Expand Down Expand Up @@ -90,8 +91,8 @@ any of the records already exists.
Update records using a Transaction
----------------------------------

:meth:`Transaction.update` updates one or more existing records in a table. Fails
if any of the records does not already exist.
:meth:`Transaction.update` updates one or more existing records in a table.
Fails if any of the records does not already exist.

.. code:: python

Expand Down Expand Up @@ -178,35 +179,40 @@ Using :meth:`~Database.run_in_transaction`

Rather than calling :meth:`~Transaction.commit` or :meth:`~Transaction.rollback`
manually, you should use :meth:`~Database.run_in_transaction` to run the
function that you need. The transaction's :meth:`~Transaction.commit` method
function that you need. The transaction's :meth:`~Transaction.commit` method
will be called automatically if the ``with`` block exits without raising an
exception. The function will automatically be retried for
exception. The function will automatically be retried for
:class:`~google.api_core.exceptions.Aborted` errors, but will raise on
:class:`~google.api_core.exceptions.GoogleAPICallError` and
:meth:`~Transaction.rollback` will be called on all others.

.. code:: python

def _unit_of_work(transaction):

transaction.insert(
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
'citizens',
columns=['email', 'first_name', 'last_name', 'age'],
values=[
['phred@exammple.com', 'Phred', 'Phlyntstone', 32],
['bharney@example.com', 'Bharney', 'Rhubble', 31],
])
]
)

transaction.update(
'citizens', columns=['email', 'age'],
'citizens',
columns=['email', 'age'],
values=[
['phred@exammple.com', 33],
['bharney@example.com', 32],
])
]
)

...

transaction.delete('citizens',
keyset['bharney@example.com', 'nonesuch@example.com'])
transaction.delete(
'citizens',
keyset=['bharney@example.com', 'nonesuch@example.com']
)

db.run_in_transaction(_unit_of_work)

Expand Down Expand Up @@ -242,7 +248,7 @@ If an exception is raised inside the ``with`` block, the transaction's
...

transaction.delete('citizens',
keyset['bharney@example.com', 'nonesuch@example.com'])
keyset=['bharney@example.com', 'nonesuch@example.com'])


Begin a Transaction
Expand Down
Loading