【问题标题】:GAE datastore query ConjunctionNode errorGAE 数据存储查询 ConjunctionNode 错误
【发布时间】:2018-08-12 09:37:15
【问题描述】:

我在数据存储区中有一个 ndb 模型,其中包含两个字段 - expired 和 expiry 除了书名、作者等其他详细信息。

class Books(ndb.Model):  
     expiry = ndb.IntegerProperty() #epoch
     expired = ndb.BooleanProperty(default=False) # set True if expiry < curr_time

我已经编写了 cron.yaml 和 cron.py 来标记 expired=True 以查找 expiry &lt; curr_time 所在的书籍。

下面是我的 cron.py sn-p:

    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

但是,我收到错误:

文件“/home/hduser/Documents/GCP/book-shelf453/default/app/cron.py”,第 16 行,在 deleteindex 中

expired_books = Books.query(ndb.AND(Books.expiry 新中的文件“/home/hduser/Documents/GCP/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py”,第 583 行 ' 收到一个非节点实例 %r' % 节点)

TypeError: ConjunctionNode() 需要 Node 实例作为参数;收到非Node实例False

我不确定这里的问题。请建议!谢谢!

【问题讨论】:

    标签: python python-2.7 google-app-engine google-cloud-datastore app-engine-ndb


    【解决方案1】:

    ndb 查询过滤器必须包含模型属性和值之间的比较 - 例如 Books.expiryint 之间的比较。

    not Books.expired不是这样比较的,这就是错误的原因。

    不要否定Books.expired,而是将其与布尔值进行比较。

    这应该可行:

    expired_books = Books.query(ndb.AND(Books.expiry &lt; curr_time, Books.expired != False))

    【讨论】:

    • 成功了,谢谢!我不得不稍微修改为expired_books = Books.query(ndb.AND(Books.expiry &lt; curr_time, Books.expired == True)),因为 GAE 抱怨一次只支持一个不等式查询。
    猜你喜欢
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多