Skip to content

Commit 95eb30b

Browse files
chore(gae): rename and delete region tags in standard/ndb/ (#13190)
* chore(gae): fix region tags in ndb/async/shopping_cart.py * chore(gae): fix region tags in ndb/queries/snippets.py * chore(gae): fix region tags in ndb/properties/snippets.py * chore(gae): rename region tags in ndb/transactions/main.py * chore(gae): unify prefixes for region tags * chore(gae): add missing prefix
1 parent ca273b2 commit 95eb30b

File tree

5 files changed

+38
-43
lines changed

5 files changed

+38
-43
lines changed

appengine/standard/ndb/async/shopping_cart.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from google.appengine.ext import ndb
1616

1717

18-
# [START models]
18+
# [START gae_ndb_async_model_classes]
1919
class Account(ndb.Model):
2020
pass
2121

@@ -32,9 +32,7 @@ class CartItem(ndb.Model):
3232

3333
class SpecialOffer(ndb.Model):
3434
inventory = ndb.KeyProperty(kind=InventoryItem)
35-
36-
37-
# [END models]
35+
# [END gae_ndb_async_model_classes]
3836

3937

4038
def get_cart_plus_offers(acct):
@@ -57,7 +55,7 @@ def get_cart_plus_offers_async(acct):
5755
return cart, offers
5856

5957

60-
# [START cart_offers_tasklets]
58+
# [START gae_ndb_async_cart_offers_tasklets]
6159
@ndb.tasklet
6260
def get_cart_tasklet(acct):
6361
cart = yield CartItem.query(CartItem.account == acct.key).fetch_async()
@@ -76,9 +74,7 @@ def get_offers_tasklet(acct):
7674
def get_cart_plus_offers_tasklet(acct):
7775
cart, offers = yield get_cart_tasklet(acct), get_offers_tasklet(acct)
7876
raise ndb.Return((cart, offers))
79-
80-
81-
# [END cart_offers_tasklets]
77+
# [END gae_ndb_async_cart_offers_tasklets]
8278

8379

8480
@ndb.tasklet

appengine/standard/ndb/properties/snippets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# [START notestore_imports]
17+
# [START gae_ndb_properties_note_store_imports]
1818
from google.appengine.ext import ndb
1919
from google.appengine.ext.ndb import msgprop
20+
# [END gae_ndb_properties_note_store_imports]
2021

21-
# [END notestore_imports]
2222
from protorpc import messages
2323

2424

appengine/standard/ndb/queries/snippets.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def query_article_inequality_explicit():
6060

6161

6262
def articles_with_tags_example():
63-
# [START included_in_inequality]
63+
# [START gae_ndb_query_included_in_inequality]
6464
Article(title="Perl + Python = Parrot", stars=5, tags=["python", "perl"])
65-
# [END included_in_inequality]
66-
# [START excluded_from_inequality]
65+
# [END gae_ndb_query_included_in_inequality]
66+
# [START gae_ndb_query_excluded_from_inequality]
6767
Article(title="Introduction to Perl", stars=3, tags=["perl"])
68-
# [END excluded_from_inequality]
68+
# [END gae_ndb_query_excluded_from_inequality]
6969

7070

7171
def query_article_in():
@@ -104,15 +104,14 @@ def query_greeting_multiple_orders():
104104

105105

106106
def query_purchase_with_customer_key():
107-
# [START purchase_with_customer_key_models]
107+
# [START gae_ndb_query_purchase_with_customer_key_models]
108108
class Customer(ndb.Model):
109109
name = ndb.StringProperty()
110110

111111
class Purchase(ndb.Model):
112112
customer = ndb.KeyProperty(kind=Customer)
113113
price = ndb.IntegerProperty()
114-
115-
# [END purchase_with_customer_key_models]
114+
# [END gae_ndb_query_purchase_with_customer_key_models]
116115

117116
def query_purchases_for_customer_via_key(customer_entity):
118117
purchases = Purchase.query(Purchase.customer == customer_entity.key).fetch()
@@ -122,14 +121,13 @@ def query_purchases_for_customer_via_key(customer_entity):
122121

123122

124123
def query_purchase_with_ancestor_key():
125-
# [START purchase_with_ancestor_key_models]
124+
# [START gae_ndb_query_purchase_with_ancestor_key_models]
126125
class Customer(ndb.Model):
127126
name = ndb.StringProperty()
128127

129128
class Purchase(ndb.Model):
130129
price = ndb.IntegerProperty()
131-
132-
# [END purchase_with_ancestor_key_models]
130+
# [END gae_ndb_query_purchase_with_ancestor_key_models]
133131

134132
def create_purchase_for_customer_with_ancestor(customer_entity):
135133
purchase = Purchase(parent=customer_entity.key)

appengine/standard/ndb/transactions/main.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
import flask
2020

21-
# [START taskq-imp]
21+
# [START gae_ndb_transactions_import]
2222
from google.appengine.api import taskqueue
2323
from google.appengine.ext import ndb
24-
25-
# [END taskq-imp]
24+
# [END gae_ndb_transactions_import]
2625

2726

2827
class Note(ndb.Model):
@@ -73,72 +72,70 @@ def main_page():
7372
return response
7473

7574

76-
# [START standard]
75+
# [START gae_ndb_transactions_insert_standard]
7776
@ndb.transactional
7877
def insert_if_absent(note_key, note):
7978
fetch = note_key.get()
8079
if fetch is None:
8180
note.put()
8281
return True
8382
return False
83+
# [END gae_ndb_transactions_insert_standard]
8484

8585

86-
# [END standard]
87-
88-
89-
# [START two-tries]
86+
# [START gae_ndb_transactions_insert_two_tries]
9087
@ndb.transactional(retries=1)
9188
def insert_if_absent_2_retries(note_key, note):
9289
# do insert
93-
# [END two-tries]
90+
# [END gae_ndb_transactions_insert_two_tries]
9491
fetch = note_key.get()
9592
if fetch is None:
9693
note.put()
9794
return True
9895
return False
9996

10097

101-
# [START cross-group]
98+
# [START gae_ndb_transactions_insert_cross_group]
10299
@ndb.transactional(xg=True)
103100
def insert_if_absent_xg(note_key, note):
104101
# do insert
105-
# [END cross-group]
102+
# [END gae_ndb_transactions_insert_cross_group]
106103
fetch = note_key.get()
107104
if fetch is None:
108105
note.put()
109106
return True
110107
return False
111108

112109

113-
# [START sometimes]
110+
# [START gae_ndb_transactions_insert_sometimes]
114111
def insert_if_absent_sometimes(note_key, note):
115112
# do insert
116-
# [END sometimes]
113+
# [END gae_ndb_transactions_insert_sometimes]
117114
fetch = note_key.get()
118115
if fetch is None:
119116
note.put()
120117
return True
121118
return False
122119

123120

124-
# [START indep]
121+
# [START gae_ndb_transactions_insert_independent]
125122
@ndb.transactional(propagation=ndb.TransactionOptions.INDEPENDENT)
126123
def insert_if_absent_indep(note_key, note):
127124
# do insert
128-
# [END indep]
125+
# [END gae_ndb_transactions_insert_independent]
129126
fetch = note_key.get()
130127
if fetch is None:
131128
note.put()
132129
return True
133130
return False
134131

135132

136-
# [START taskq]
133+
# [START gae_ndb_transactions_insert_task_queue]
137134
@ndb.transactional
138135
def insert_if_absent_taskq(note_key, note):
139136
taskqueue.add(url=flask.url_for("taskq_worker"), transactional=True)
140137
# do insert
141-
# [END taskq]
138+
# [END gae_ndb_transactions_insert_task_queue]
142139
fetch = note_key.get()
143140
if fetch is None:
144141
note.put()
@@ -154,17 +151,17 @@ def taskq_worker():
154151
def pick_random_insert(note_key, note):
155152
choice = random.randint(0, 5)
156153
if choice == 0:
157-
# [START calling2]
154+
# [START gae_ndb_transactions_insert_standard_calling_2]
158155
inserted = insert_if_absent(note_key, note)
159-
# [END calling2]
156+
# [END gae_ndb_transactions_insert_standard_calling_2]
160157
elif choice == 1:
161158
inserted = insert_if_absent_2_retries(note_key, note)
162159
elif choice == 2:
163160
inserted = insert_if_absent_xg(note_key, note)
164161
elif choice == 3:
165-
# [START sometimes-call]
162+
# [START gae_ndb_transactions_insert_sometimes_callback]
166163
inserted = ndb.transaction(lambda: insert_if_absent_sometimes(note_key, note))
167-
# [END sometimes-call]
164+
# [END gae_ndb_transactions_insert_sometimes_callback]
168165
elif choice == 4:
169166
inserted = insert_if_absent_indep(note_key, note)
170167
elif choice == 5:
@@ -183,10 +180,10 @@ def add_note():
183180
choice = random.randint(0, 1)
184181
if choice == 0:
185182
# Use transactional function
186-
# [START calling]
183+
# [START gae_ndb_transactions_insert_standard_calling_1]
187184
note_key = ndb.Key(Note, note_title, parent=parent)
188185
note = Note(key=note_key, content=note_text)
189-
# [END calling]
186+
# [END gae_ndb_transactions_insert_standard_calling_1]
190187
if pick_random_insert(note_key, note) is False:
191188
return 'Already there<br><a href="%s">Return</a>' % flask.url_for(
192189
"main_page", page_name=page_name
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# pin pytest to 4.6.11 for Python2.
22
pytest==4.6.11; python_version < '3.0'
3+
4+
# pytest==8.3.4 and six==1.17.0 for Python3.
5+
pytest==8.3.4; python_version >= '3.0'
6+
six==1.17.0

0 commit comments

Comments
 (0)