I am porting an app from Google App Engine to AppScale, and have discovered peculiar behaviour when performing ancestor queries on entity groups.
If I perform an ancestor query where the parent is not the root, the query returns zero results. If I perform the same query with the parent as root, the correct results are returned.
Easiest to illustrate with an example:
class A(ndb.Model):
name = ndb.StringProperty()
class B(ndb.Model):
name = ndb.StringProperty()
class C(ndb.Model):
name = ndb.StringProperty()
active = ndb.BooleanProperty()
sort = ndb.IntegerProperty()
def main():
a = A(name='I am A')
a.put()
b = B(parent=a.key,
name='I am B')
b.put()
C(parent=b.key,
name='I am C1',
active=True,
sort=0).put()
C(parent=b.key,
name='I am C2',
active=True,
sort=1).put()
C(parent=b.key,
name='I am C3',
active=True,
sort=2).put()
query1 = C.query(C.active == True, ancestor=a.key).order(C.sort).fetch(10)
query2 = C.query(C.active == True, ancestor=b.key).order(C.sort).fetch(10)
print 'query 1 = %s' % len(query1)
print 'query 2 = %s' % len(query2)
If I run the above code on App Engine I get 3 results for both queries. If I run it on AppScale, then I only get 3 results for the first query, and 0 results for the second query.
AppScale uses Cassandra as the datastore. Is this a subtle difference in behaviour between the App Engine datastore and Cassandra?
This is a bug in AppScale where we used the full path of the provided ancestor and not just its root entity for composite queries. The fix for it can be found here: https://github.com/AppScale/appscale/pull/1633