如何在Datastore Plus(NDB)中查询Model.KeyProperty == None

2 投票
1 回答
1864 浏览
提问于 2025-04-17 04:04

假设有一个NDB(版本0.7和0.8)模型,其中的键可以是None(也就是没有值)。

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'

我该如何查询键属性为None的情况呢?

1 个回答

1

这看起来像是NDB里的一个错误。你能在问题追踪系统上提交一个吗?

撰写回答