Reputation: 458
I have a ndb model in datastore with two fields - expired and expiry besides other details such as bookname, author etc.
class Books(ndb.Model):
expiry = ndb.IntegerProperty() #epoch
expired = ndb.BooleanProperty(default=False) # set True if expiry < curr_time
I have written cron.yaml and cron.py to mark expired=True
for finding the books where the expiry < curr_time
.
Following is my cron.py snippet:
from google.appengine.api import search
import logging
from models.books import Books
from google.appengine.ext import ndb
import time
def deleteindex(cls):
curr_time = int(time.time()) + 60
#find the books which have expired but not marked expired.
expired_books = Books.query(ndb.AND(Books.expiry < curr_time, not Books.expired))
print expired_books
However, I am getting error :
File "/home/hduser/Documents/GCP/book-shelf453/default/app/cron.py", line 16, in deleteindex
expired_books = Books.query(ndb.AND(Books.expiry < curr_time, not Books.expired)) File "/home/hduser/Documents/GCP/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 583, in new ' received a non-Node instance %r' % node)
TypeError: ConjunctionNode() expects Node instances as arguments; received a non-Node instance False
I am not sure about the issue here. Please suggest ! Thanks!
Upvotes: 1
Views: 151
Reputation: 55894
ndb query filters must consist of comparisons between a model property and a value - for example between Books.expiry
and an int
.
not Books.expired
is not such a comparison, and this is the cause of the error.
Instead of negating Books.expired
, compare it to a boolean.
This should work:
expired_books = Books.query(ndb.AND(Books.expiry < curr_time, Books.expired != False))
Upvotes: 1