Questions tagged [app-engine-ndb]

NDB is a better datastore API for the Google App Engine Python runtime. It provides an improved interface over ext.db, and includes support for parallel processing with coroutines.

NDB is a better datastore API for the Google App Engine Python runtime, and currently a standard component of the App Engine Python SDK and the Python runtime.

The NDB API provides persistent storage in a schemaless object datastore. It supports automatic caching, sophisticated queries, and atomic transactions. NDB is well-suited to storing structured data records.

Documentation.

Conversion guide from old db.

Original [deprecated] project.

1288 questions
10
votes
1 answer

How do I know if ndb.Model.get_or_insert created a new entity or got an existing one?

For the following (broken) function, I want to return True if the entity was created or updated, and False otherwise. The problem is that I do not know whether get_or_insert() got an existing entity, or inserted one. Is there an easy way to…
Matt Faus
  • 6,321
  • 2
  • 27
  • 43
10
votes
1 answer

Using @ndb.tasklet or @ndb.synctasklet in Google App Engine

I have a POST method which calls a few tasklets. These tasklets do have yields in them, and I do have some x.put_async() in my code. So I don't want it to return before all the async stuff is done. So I decorated all my tasklets, which are just…
Snowman
  • 31,411
  • 46
  • 180
  • 303
10
votes
2 answers

Querying a repeated property by count in NDB

Is there an efficient mechanism for querying by the number of items in a repeated property in NDB? I'd like to do something like: Class.query(class.repeated_property.count == 2) but of course this doesn't work.
KitB
  • 510
  • 2
  • 16
10
votes
1 answer

What's the equivalent of Entity.all(keys_only=True).fetch(20) in NDB?

How do I get the equivalent result of the following query in NDB? Entity.all(keys_only=True).fetch(20) I know you can pass 'keys_only=True' to the iter() method. But what if I want to perform a keys only fetch, how do I do that in NDB?
Albert
  • 3,611
  • 3
  • 28
  • 52
9
votes
4 answers

looking for ideas/alternatives to providing a page/item count/navigation of items matching a GAE datastore query

I like the datastore simplicity, scalability and ease of use; and the enhancements found in the new ndb library are fabulous. As I understand datastore best practices, one should not write code to provide item and/or page counts of matching query…
9
votes
1 answer

GAE/P: Transaction safety with API calls

Suppose you use a transaction to process a Stripe payment and update a user entity: @ndb.transactional def process_payment(user_key, amount): user = user_key.get() user.stripe_payment(amount) # API call to Stripe user.balance += amount …
new name
  • 15,861
  • 19
  • 68
  • 114
9
votes
2 answers

Using ndb.KeyProperty how to reference the same model?

I have a simple scenario where there is a User class which has the name, email and followers property. class User(ndb.Model): name = ndb.StringProperty(required = True) search_name = ndb.StringProperty(required = True) pw_hash =…
8
votes
1 answer

Does the automatic use of caching in NDB, the Google App Engine Datastore library for Python, invalidate the transaction model?

A major selling point of Google Cloud Datastore is that it provides strong consistency within an entity group. Cloud Datastore ensures that entity lookups by key and ancestor queries always receive strongly consistent data. [Datastore is good for]…
8
votes
3 answers

Memory leak in Google ndb library

I think there is a memory leak in the ndb library but I can not find where. Is there a way to avoid the problem described below? Do you have a more accurate idea of testing to figure out where the problem is? That's how I reproduced the problem : I…
greg
  • 2,339
  • 1
  • 18
  • 23
8
votes
1 answer

NDB: Query for unset properties?

I've had some data being gathered in production for a couple of days with, lets say, the following model: class Tags(ndb.Model): dt_added = ndb.DateTimeProperty(auto_now_add=True) s_name = ndb.StringProperty(required=True,…
8
votes
1 answer

Many-To-Many Relationship in ndb

Trying to model a many-to-many relationship with ndb. Can anyone point to a good example of how to do this? At here is an example of what I have at the moment: class Person(ndb.Model): guilds = ndb.KeyProperty(kind="Guild",…
chrisw
  • 273
  • 1
  • 4
  • 11
8
votes
1 answer

How to read old property values in a _pre_put_hook

I am trying to implement an ndb model audit so that all changes to properties are stored within each model instance. Here is the code of the _pre_put_hook I chose to implement that. def _pre_put_hook(self): # save a history record for updates …
8
votes
2 answers

How to fix index error when querying GAE datastore?

When I try to run a query on the datastore ordered by date I get the following error: NeedIndexError: no matching index found. The suggested index for this query is: - kind: Message properties: - name: author - name: ref - name: date The…
deltanine
  • 1,166
  • 1
  • 13
  • 25
8
votes
3 answers

Using yield with multiple ndb.get_multi_async

I am trying to improve efficiency of my current query from appengine datastore. Currently, I am using a synchronous method: class Hospital(ndb.Model): name = ndb.StringProperty() buildings=…
Jon
  • 734
  • 1
  • 7
  • 30
8
votes
3 answers

In practice, how eventual is the "eventual consistency" in HRD?

I am in the process of migrating an application from Master/Slave to HRD. I would like to hear some comments from who already went through the migration. I tried a simple example to just post a new entity without ancestor and redirecting to a page…
schettino72
  • 2,990
  • 1
  • 28
  • 27
1 2
3
85 86