【问题标题】:How to query Model.KeyProperty == None in Datastore Plus(NDB)如何在 Datastore Plus(NDB) 中查询 Model.KeyProperty == None
【发布时间】:2011-10-11 09:56:48
【问题描述】:

假设一个 NDB(版本 0.7 和 0.8)模型的键可以是无:

class Test(model.Model):
    k = model.KeyProperty()
    value = model.IntegerProperty()

 count = Test.query(Test.k == None).count() # error
 #count = Test.query(Test.k != None).count() # error also

仅过滤键为 None 会引发错误。

File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
    handler.get(*groups)
File "/Users/reiot/Documents/Works/ndbtest/main.py", line 91, in get
    count = Test.query(Test.k == None).count() # error
File "/Users/reiot/Documents/Works/ndbtest/ndb/model.py", line 500, in __eq__
    return self._comparison('=', value)
File "/Users/reiot/Documents/Works/ndbtest/ndb/model.py", line 491, in _comparison
    return FilterNode(self._name, op, self._datastore_type(value))
File "/Users/reiot/Documents/Works/ndbtest/ndb/model.py", line 1138, in _datastore_type
    return datastore_types.Key(value.urlsafe())
AttributeError: 'NoneType' object has no attribute 'urlsafe'

如何查询无的 KeyProperty?

【问题讨论】:

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


    【解决方案1】:

    这看起来像是 NDB 中的一个错误。您可以在问题跟踪器上提交一份吗?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多