Skip to content

Commit 539d4b9

Browse files
authored
Remove bogus examples of 'database.transaction()'. (googleapis#6032)
Use 'session.transaction()' instead. Use ReST markup to set off notes about manual transaction usage. Closes googleapis#6029.
1 parent d072d0d commit 539d4b9

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

spanner/docs/transaction-usage.rst

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@ To understand more about how transactions work, visit :ref:`spanner-txn`.
99
To learn more about how to use them in the Python client, continue reading.
1010

1111

12-
Begin a Transaction
13-
-------------------
14-
15-
To begin using a transaction:
16-
17-
.. code:: python
18-
19-
transaction = database.transaction()
20-
21-
2212
Read Table Data
2313
---------------
2414

2515
Read data for selected rows from a table in the database. Calls the ``Read``
26-
API, which returns all rows specified in ``key_set``, or else fails if the
16+
API, which returns all rows specified in ``key_set``, or else fails if the
2717
result set is too large,
2818

2919
.. code:: python
@@ -205,7 +195,7 @@ exception. The function will automatically be retried for
205195
206196
transaction.delete('citizens',
207197
keyset['bharney@example.com', 'nonesuch@example.com'])
208-
198+
209199
db.run_in_transaction(_unit_of_work)
210200
211201
@@ -221,7 +211,7 @@ If an exception is raised inside the ``with`` block, the transaction's
221211

222212
.. code:: python
223213
224-
with database.transaction() as transaction:
214+
with session.transaction() as transaction:
225215
226216
transaction.insert(
227217
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
@@ -243,12 +233,30 @@ If an exception is raised inside the ``with`` block, the transaction's
243233
keyset['bharney@example.com', 'nonesuch@example.com'])
244234
245235
236+
Begin a Transaction
237+
-------------------
238+
239+
.. note::
240+
241+
Normally, applications will not construct transactions manually. Rather,
242+
consider using :meth:`~Database.run_in_transaction` or the context manager
243+
as described above.
244+
245+
To begin using a transaction manually:
246+
247+
.. code:: python
248+
249+
transaction = session.transaction()
250+
251+
246252
Commit changes for a Transaction
247253
--------------------------------
248254

249-
This function should not be used manually. Rather, should consider using
250-
:meth:`~Database.run_in_transaction` or the context manager as described
251-
above.
255+
.. note::
256+
257+
Normally, applications will not commit transactions manually. Rather,
258+
consider using :meth:`~Database.run_in_transaction` or the context manager
259+
as described above.
252260

253261
After modifications to be made to table data via the
254262
:meth:`Transaction.insert`, :meth:`Transaction.update`,
@@ -265,9 +273,11 @@ API call.
265273
Roll back changes for a Transaction
266274
-----------------------------------
267275

268-
This function should not be used manually. Rather, should consider using
269-
:meth:`~Database.run_in_transaction` or the context manager as described
270-
above.
276+
.. note::
277+
278+
Normally, applications will not roll back transactions manually. Rather,
279+
consider using :meth:`~Database.run_in_transaction` or the context manager
280+
as described above.
271281

272282
After describing the modifications to be made to table data via the
273283
:meth:`Transaction.insert`, :meth:`Transaction.update`,

0 commit comments

Comments
 (0)