8000 Merge pull request #689 from dhermes/fix-685 · googleapis/google-cloud-python@3c7316e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c7316e

Browse files
committed
Merge pull request #689 from dhermes/fix-685
Removing datastore.set_defaults() from all docs.
2 parents ef1a3da + 98bbd4a commit 3c7316e

File tree

7 files changed

+12
-23
lines changed

7 files changed

+12
-23
lines changed

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ with the Cloud Datastore using this Client Library.
6464
.. code:: python
6565
6666
from gcloud import datastore
67-
datastore.set_defaults()
6867
# Create, populate and persist an entity
6968
entity = datastore.Entity(key=datastore.Key('EntityKind'))
7069
entity.update({

docs/_components/datastore-getting-started.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Add some data to your dataset
3838
Open a Python console and...
3939

4040
>>> from gcloud import datastore
41-
>>> datastore.set_defaults()
4241
>>> list(datastore.Query(kind='Person').fetch())
4342
[]
4443
>>> entity = datastore.Entity(key=datastore.Key('Person'))

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Cloud Datastore
3030
.. code-block:: python
3131
3232
from gcloud import datastore
33-
datastore.set_defaults()
3433
3534
entity = datastore.Entity(key=datastore.Key('Person'))
3635
entity['name'] = 'Your name'

gcloud/datastore/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
1919
>>> from gcloud import datastore
2020
21-
>>> datastore.set_defaults()
22-
2321
>>> key = datastore.Key('EntityKind', 1234)
2422
>>> entity = datastore.Entity(key)
2523
>>> query = datastore.Query(kind='EntityKind')

gcloud/datastore/connection.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def lookup(self, dataset_id, key_pbs,
147147
under the hood in :func:`gcloud.datastore.get`:
148148
149149
>>> from gcloud import datastore
150-
>>> datastore.set_defaults()
151150
>>> key = datastore.Key('MyKind', 1234, dataset_id='dataset-id')
152151
>>> datastore.get([key])
153152
[<Entity object>]
@@ -210,8 +209,6 @@ def run_query(self, dataset_id, query_pb, namespace=None,
210209
211210
>>> from gcloud import datastore
212211
213-
>>> datastore.set_defaults()
214-
215212
>>> query = datastore.Query(kind='MyKind')
216213
>>> query.add_filter('property', '=', 'val')
217214

gcloud/datastore/demo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323

2424

2525
def initialize():
26-
datastore.set_defaults(dataset_id=DATASET_ID)
26+
datastore.set_default_dataset_id(DATASET_ID)

gcloud/datastore/transaction.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,21 @@ class Transaction(Batch):
2828
mutation, and execute those within a transaction::
2929
3030
>>> from gcloud import datastore
31-
>>> from gcloud.datastore.transaction import Transaction
3231
33-
>>> datastore.set_defaults()
34-
35-
>>> with Transaction():
32+
>>> with datastore.Transaction():
3633
... datastore.put([entity1, entity2])
3734
3835
Because it derives from :class:`Batch`, :class`Transaction` also provides
3936
:meth:`put` and :meth:`delete` methods::
4037
41-
>>> with Transaction() as xact:
38+
>>> with datastore.Transaction() as xact:
4239
... xact.put(entity1)
4340
... xact.delete(entity2.key)
4441
4542
By default, the transaction is rolled back if the transaction block
4643
exits with an error::
4744
48-
>>> with Transaction():
45+
>>> with datastore.Transaction():
4946
... do_some_work()
5047
... raise SomeException() # rolls back
5148
@@ -56,8 +53,8 @@ class Transaction(Batch):
5653
entities will not be available at save time! That means, if you
5754
try::
5855
59-
>>> with Transaction():
60-
... entity = Entity(key=Key('Thing'))
56+
>>> with datastore.Transaction():
57+
... entity = datastore.Entity(key=Key('Thing'))
6158
... datastore.put([entity])
6259
6360
``entity`` won't have a complete Key until the transaction is
@@ -66,8 +63,8 @@ class Transaction(Batch):
6663
Once you exit the transaction (or call ``commit()``), the
6764
automatically generated ID will be assigned to the entity::
6865
69-
>>> with Transaction():
70-
... entity = Entity(key=Key('Thing'))
66+
>>> with datastore.Transaction():
67+
... entity = datastore.Entity(key=Key('Thing'))
7168
... datastore.put([entity])
7269
... assert entity.key.is_partial # There is no ID on this key.
7370
...
@@ -76,15 +73,15 @@ class Transaction(Batch):
7673
After completion, you can determine if a commit succeeded or failed.
7774
For example, trying to delete a key that doesn't exist::
7875
79-
>>> with Transaction() as xact:
76+
>>> with datastore.Transaction() as xact:
8077
... xact.delete(key)
8178
...
8279
>>> xact.succeeded
8380
False
8481
8582
or successfully storing two entities:
8683
87-
>>> with Transaction() as xact:
84+
>>> with datastore.Transaction() as xact:
8885
... datastore.put([entity1, entity2])
8986
...
9087
>>> xact.succeeded
@@ -93,10 +90,10 @@ class Transaction(Batch):
9390
If you don't want to use the context manager you can initialize a
9491
transaction manually::
9592
96-
>>> transaction = Transaction()
93+
>>> transaction = datastore.Transaction()
9794
>>> transaction.begin()
9895
99-
>>> entity = Entity(key=Key('Thing'))
96+
>>> entity = datastore.Entity(key=Key('Thing'))
10097
>>> transaction.put(entity)
10198
10299
>>> if error:

0 commit comments

Comments
 (0)
0