我如何测试Appengine中ReferenceProperty的有效性? [英] How can I test the validity of a ReferenceProperty in Appengine?
问题描述
我想向我的代码添加一些检查,以确保引用的对象存在并相应地执行。 (当然,我还需要清理我的数据)。
一种方法是试图获取()它;然而,这应该可能检索整个对象 - 我想要一种方法来检测对象的存在,理想情况下,只是导致数据存储上的键操作成本,而不是完整的实体读取。
所以,我的问题如下:是否有一个简单的机制来测试给定的ReferenceProperty是否有效,只涉及关键访问操作(而不是完整的实体获取操作)? b $ b
这将在不返回实体的情况下测试关键存在:
db.Query(keys_only = True).filter('__ key__ =',test_key).count(1)== 1
I我不确定它在获取实体方面的计算便宜。
I am currently testing a small application I have written. I have not been sufficiently careful in ensuring the data in my datastore is consistent and now I have an issue that I have some records referencing objects which no longer exist. More specifially, I have some objects which have ReferenceProperty's which have been assigned values; the objects referred to have been deleted but the reference remains.
I would like to add some checks to my code to ensure that referenced objects exist and acting accordingly. (Of course, I also need to clean up my data).
One approach is to just try to get() it; however, this should probably retrieve the entire object - I'd like an approach which just tests the existence of the object, ideally, just resulting in costs of key manipulations on the datastore, rather than full entity reads.
So, my question is the following: is there a simple mechanism to test if a given ReferenceProperty is valid which only involves key access operations (rather than full entity get operations)?
This will test key existence without returning an entity:
db.Query(keys_only=True).filter('__key__ =', test_key).count(1) == 1
I'm not certain that it's computationally cheaper than fetching the entity.
这篇关于我如何测试Appengine中ReferenceProperty的有效性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!