Does NDB still index with default=None or properti

2019-07-22 02:02发布

I'd like to be able to run a query like: MyModel.query(MyModel.some_property == None) and get results. I know that if I don't put a default=<some default> in a property, I won't be able to query for it, but if I set default=None will it index it?

Similarly, does setting values to None cause properties to be indexed in ndb.Model? What if you pass some_keyword_arg=None to the constructor?

I know that doing something like: ndb.StringProperty(default='') means you can query on it, just not clear on the semantics of using None.

1条回答
祖国的老花朵
2楼-- · 2019-07-22 02:48

Explicitly setting a property to None is defining a value, and yes defaults work and the property will be indexed. This assumes None is a valid value for a particular property type.

Some issues will arise, as you pointed out, often you use None as a sentinal value, so how do you tell between no Value provided and an explicit None?

查看更多
登录 后发表回答