使用ComputedProperty安全么?
我需要在App Engine中支持计算属性。我下载了最新的源代码,想自己实现这些功能。在查看代码时,我发现有一个属性类,似乎已经完全满足我的需求。
class ComputedProperty(Property):
"""Property used for creating properties derived from other values.
Certain attributes should never be set by users but automatically
calculated at run-time from other values of the same entity. These
values are implemented as persistent properties because they provide
useful search keys.
...
"""
不过,这个类没有文档说明;我在官方文档中找不到关于ComputedProperty
的任何信息。
那么,ComputedProperty
可以安全使用吗?它会有bug吗?或者说将来可能会改变吗?
2 个回答
3
这些功能已经上线并且有了相关的文档,至少对于NDB API来说是这样的:
https://developers.google.com/appengine/docs/python/ndb/properties#computed
7
ComputedProperty
看起来像是一个“端口”(这个词可能不太准确),它是一个自定义属性类的变种,这个类叫做 DerivedProperty
,这个概念来自Nick Johnson的博客。
因为Nick的博客展示了创建一个自定义数据存储 Property
类是多么简单,所以我觉得不需要太担心 ComputedProperty
。如果有需要,你总是可以用自己创建的 Property
子类来替换它。