NDB Google App Engine Ancestor Request Not Set

I am trying to execute the following query:

query = Comment.query(ancestor = userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate)) 

The 1 equal sign (=) is how docs said that we should have it, but my application does not start when I have only one equal sign (build error). If I use two equal signs, for example ancestor == userKey , the application starts, but I get NameError: global name 'ancestor' is not defined . What gives?

I also tried a different version of this query, but the same problem occurs:

 query = Comment.query(ndb.AND(ancestor == userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))) 
+4
source share
1 answer

You need to put the ancestor keyword after the positional parameters of the method:

 query = Comment.query( ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate), ancestor=userKey) 

Alternatively, use the filters keyword explicitly or use the .filter() method:

 query = Comment.query( ancestor=userKey, filters=ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate)) 

or

 query = Comment.query(ancestor=userKey).filter(ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate)) 
+6
source

Source: https://habr.com/ru/post/1432316/


All Articles