Non-root group queries return zero results
I am migrating an application from Google App Engine to AppScale and found some peculiar behavior when making ancestor queries on entity groups.
If I execute an ancestor query where the parent is not the root, the query returns null results. If I run the same query with the parent name root, correct results are returned.
The easiest way to illustrate is 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 requests. If I run it in AppScale, then I only get 3 results for the first query and 0 results for the second query.
AppScale uses Cassandra as its data store. Is this a subtle difference in behavior between App Engine and Cassandra datastore?
source to share
This is a bug in AppScale where we used the full path of the provided ancestor, not just its root entity, for compound queries. You can fix it here: https://github.com/AppScale/appscale/pull/1633
source to share