Skip to content

Commit

Permalink
Merge pull request #689 from dhermes/fix-685
Browse files Browse the repository at this point in the history
Removing datastore.set_defaults() from all docs.
  • Loading branch information
dhermes committed Mar 9, 2015
2 parents ef1a3da + 98bbd4a commit 3c7316e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ with the Cloud Datastore using this Client Library.
.. code:: python
from gcloud import datastore
datastore.set_defaults()
# Create, populate and persist an entity
entity = datastore.Entity(key=datastore.Key('EntityKind'))
entity.update({
Expand Down
1 change: 0 additions & 1 deletion docs/_components/datastore-getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Add some data to your dataset
Open a Python console and...

>>> from gcloud import datastore
>>> datastore.set_defaults()
>>> list(datastore.Query(kind='Person').fetch())
[]
>>> entity = datastore.Entity(key=datastore.Key('Person'))
Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Cloud Datastore
.. code-block:: python
from gcloud import datastore
datastore.set_defaults()
entity = datastore.Entity(key=datastore.Key('Person'))
entity['name'] = 'Your name'
Expand Down
2 changes: 0 additions & 2 deletions gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
>>> from gcloud import datastore
>>> datastore.set_defaults()
>>> key = datastore.Key('EntityKind', 1234)
>>> entity = datastore.Entity(key)
>>> query = datastore.Query(kind='EntityKind')
Expand Down
3 changes: 0 additions & 3 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def lookup(self, dataset_id, key_pbs,
under the hood in :func:`gcloud.datastore.get`:
>>> from gcloud import datastore
>>> datastore.set_defaults()
>>> key = datastore.Key('MyKind', 1234, dataset_id='dataset-id')
>>> datastore.get([key])
[<Entity object>]
Expand Down Expand Up @@ -210,8 +209,6 @@ def run_query(self, dataset_id, query_pb, namespace=None,
>>> from gcloud import datastore
>>> datastore.set_defaults()
>>> query = datastore.Query(kind='MyKind')
>>> query.add_filter('property', '=', 'val')
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@


def initialize():
datastore.set_defaults(dataset_id=DATASET_ID)
datastore.set_default_dataset_id(DATASET_ID)
25 changes: 11 additions & 14 deletions gcloud/datastore/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@ class Transaction(Batch):
mutation, and execute those within a transaction::
>>> from gcloud import datastore
>>> from gcloud.datastore.transaction import Transaction
>>> datastore.set_defaults()
>>> 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
Expand All @@ -56,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
Expand All @@ -66,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.
...
Expand All @@ -76,15 +73,15 @@ 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
False
or successfully storing two entities:
>>> with Transaction() as xact:
>>> with datastore.Transaction() as xact:
... datastore.put([entity1, entity2])
...
>>> xact.succeeded
Expand All @@ -93,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:
Expand Down

0 comments on commit 3c7316e

Please sign in to comment.