@@ -28,21 +28,21 @@ class Transaction(Batch):
2828 mutation, and execute those within a transaction::
2929
3030 >>> from gcloud import datastore
31-
32- >>> with datastore.Transaction ():
33- ... datastore .put_multi([entity1, entity2])
31+ >>> client = datastore.Client()
32+ >>> with client.transaction ():
33+ ... client .put_multi([entity1, entity2])
3434
3535 Because it derives from :class:`Batch <.datastore.batch.Batch>`,
3636 :class:`Transaction` also provides :meth:`put` and :meth:`delete` methods::
3737
38- >>> with datastore.Transaction () as xact:
38+ >>> with client.transaction () as xact:
3939 ... xact.put(entity1)
4040 ... xact.delete(entity2.key)
4141
4242 By default, the transaction is rolled back if the transaction block
4343 exits with an error::
4444
45- >>> with datastore.Transaction ():
45+ >>> with client.transaction ():
4646 ... do_some_work()
4747 ... raise SomeException() # rolls back
4848
@@ -53,34 +53,34 @@ class Transaction(Batch):
5353 entities will not be available at save time! That means, if you
5454 try::
5555
56- >>> with datastore.Transaction ():
57- ... entity = datastore.Entity(key=Key ('Thing'))
58- ... datastore .put(entity)
56+ >>> with client.transaction ():
57+ ... entity = datastore.Entity(key=client.key ('Thing'))
58+ ... client .put(entity)
5959
60- ``entity`` won't have a complete Key until the transaction is
60+ ``entity`` won't have a complete key until the transaction is
6161 committed.
6262
6363 Once you exit the transaction (or call :meth:`commit`), the
6464 automatically generated ID will be assigned to the entity::
6565
66- >>> with datastore.Transaction ():
67- ... entity = datastore.Entity(key=Key ('Thing'))
68- ... datastore .put(entity)
69- ... print entity.key.is_partial # There is no ID on this key.
66+ >>> with client.transaction ():
67+ ... entity = datastore.Entity(key=client.key ('Thing'))
68+ ... client .put(entity)
69+ ... print( entity.key.is_partial) # There is no ID on this key.
7070 ...
7171 True
72- >>> print entity.key.is_partial # There *is* an ID.
72+ >>> print( entity.key.is_partial) # There *is* an ID.
7373 False
7474
7575 If you don't want to use the context manager you can initialize a
7676 transaction manually::
7777
78- >>> transaction = datastore.Transaction ()
78+ >>> transaction = client.transaction ()
7979 >>> transaction.begin()
80-
81- >>> entity = datastore.Entity(key=Key ('Thing'))
80+ >>>
81+ >>> entity = datastore.Entity(key=client.key ('Thing'))
8282 >>> transaction.put(entity)
83-
83+ >>>
8484 >>> if error:
8585 ... transaction.rollback()
8686 ... else:
0 commit comments