我如何测试Appengine中ReferenceProperty的有效性? [英] How can I test the validity of a ReferenceProperty in Appengine?

查看:74
本文介绍了我如何测试Appengine中ReferenceProperty的有效性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试我写的一个小应用程序。我没有足够小心地确保数据存储区中的数据一致,现在我遇到了一些问题,我有一些记录引用了不再存在的对象。更具体地说,我有一些具有ReferenceProperty的对象,它们被分配了值;所引用的对象已被删除,但引用仍然存在。



我想向我的代码添加一些检查,以确保引用的对象存在并相应地执行。 (当然,我还需要清理我的数据)。

一种方法是试图获取()它;然而,这应该可能检索整个对象 - 我想要一种方法来检测对象的存在,理想情况下,只是导致数据存储上的键操作成本,而不是完整的实体读取。



所以,我的问题如下:是否有一个简单的机制来测试给定的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆