From 98bbd4af198ba7b9da6ba9f0cee318767be27472 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 9 Mar 2015 11:37:40 -0700 Subject: [PATCH] Removing full import of Transaction from docstrings. Fixes #684. --- gcloud/datastore/transaction.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gcloud/datastore/transaction.py b/gcloud/datastore/transaction.py index 489634f4d2a5..7e0d461dce7b 100644 --- a/gcloud/datastore/transaction.py +++ b/gcloud/datastore/transaction.py @@ -28,22 +28,21 @@ class Transaction(Batch): mutation, and execute those within a transaction:: >>> from gcloud import datastore - >>> from gcloud.datastore.transaction import Transaction - >>> with Transaction(): + >>> with datastore.Transaction(): ... datastore.put([entity1, entity2]) Because it derives from :class:`Batch`, :class`Transaction` also provides :meth:`put` and :meth:`delete` methods:: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... xact.put(entity1) ... xact.delete(entity2.key) By default, the transaction is rolled back if the transaction block exits with an error:: - >>> with Transaction(): + >>> with datastore.Transaction(): ... do_some_work() ... raise SomeException() # rolls back @@ -54,8 +53,8 @@ class Transaction(Batch): entities will not be available at save time! That means, if you try:: - >>> with Transaction(): - ... entity = Entity(key=Key('Thing')) + >>> with datastore.Transaction(): + ... entity = datastore.Entity(key=Key('Thing')) ... datastore.put([entity]) ``entity`` won't have a complete Key until the transaction is @@ -64,8 +63,8 @@ class Transaction(Batch): Once you exit the transaction (or call ``commit()``), the automatically generated ID will be assigned to the entity:: - >>> with Transaction(): - ... entity = Entity(key=Key('Thing')) + >>> with datastore.Transaction(): + ... entity = datastore.Entity(key=Key('Thing')) ... datastore.put([entity]) ... assert entity.key.is_partial # There is no ID on this key. ... @@ -74,7 +73,7 @@ class Transaction(Batch): After completion, you can determine if a commit succeeded or failed. For example, trying to delete a key that doesn't exist:: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... xact.delete(key) ... >>> xact.succeeded @@ -82,7 +81,7 @@ class Transaction(Batch): or successfully storing two entities: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... datastore.put([entity1, entity2]) ... >>> xact.succeeded @@ -91,10 +90,10 @@ class Transaction(Batch): If you don't want to use the context manager you can initialize a transaction manually:: - >>> transaction = Transaction() + >>> transaction = datastore.Transaction() >>> transaction.begin() - >>> entity = Entity(key=Key('Thing')) + >>> entity = datastore.Entity(key=Key('Thing')) >>> transaction.put(entity) >>> if error: