Google Cloud Datastore is a non-relational database and is based on the concept of possible consistency . It also provides the means to ensure strong consistency through requests from ancestors and groups of objects . However, I do not get strong consistency when using ancestor queries in transaction .
Consider this:
class Child(ndb.Model): @classmethod def create(cls): child = cls() child.put() print Child.query().fetch() Child.create()
Since this did not use an entity group, it works with a possible sequence. As expected, we get:
[]
Try using it with entity groups and ancestor query:
class Parent(ndb.Model): pass class Child(ndb.Model): @classmethod def create(cls, parent): child = cls(parent=parent) child.put() print Child.query(ancestor=parent).fetch() parent = Parent().put() Child.create(parent)
Here we get strong consistency, so the conclusion is:
[Child(key=Key('Parent', <id>, 'Child', <id>))]
However, when we translate the transaction into a mix:
class Parent(ndb.Model): pass class Child(ndb.Model): @classmethod @ndb.transactional def create(cls, parent): child = cls(parent=parent) child.put() print Child.query(ancestor=parent).fetch() parent = Parent().put() Child.create(parent)
Output:
[]
Given that translations are primarily designed to work with ancestral requests (a cross-group flag even exists only to circumvent this requirement), why does a strong consistency get lost inside a transaction?