我在谷歌应用程序引擎数据存储中的实体关系中遇到了一个非常奇怪的问题。我正在开发一个 Python/GAE Web 应用程序(学习练习),完整的代码可以在来源锻造 http://rhs-galleries.svn.sourceforge.net/viewvc/rhs-galleries/?pathrev=49.
- I have 2 models:
-
- 搜索词和(间接)照片列表
-
- 有关照片的信息,以及它所属的图库(collection_index='photos')
- 我有一个创建画廊并向其中添加照片的摄取过程
- 我有一个页面,它从数据存储区读取图库并使用该图库实例的“.photos”属性来获取其中的照片列表
现在这就是奇怪的部分出现的地方......如果我更改文件(我测试过的任何文件),或者甚至只是更新文件的时间戳(即,因此它会重新加载)...画廊的“.photos”属性开始失败。例如,如果我尝试加载“花”画廊页面 http://localhost:8080/gallery/flowers:
Traceback (most recent call last):
File "C:\Applications\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 700, in __call__ handler.get(*groups)
File "C:\Eclipse-Workspace\galleries-google\app\views\gallery.py", line 33, in get for photo in gallery.photos:
AttributeError: 'Gallery' object has no attribute 'photos'
我可以重新启动 web 应用程序,我可以重新启动应用程序启动器,然后启动 web 应用程序。不管怎样,问题仍然存在。看来我需要强制数据存储以某种方式“记住”连接
# Reading the list of photos for a given gallery via the Photo entity
# This seems to force the datastore to "remember" the connection between the two
from google.appengine.ext import db
import pprint
from app.models.gallery import Gallery
from app.models.photo import Photo
gallery = Gallery.get_by_key_name('candy')
print("Gallery: " + gallery.search_term)
q = db.GqlQuery("SELECT * FROM Photo WHERE gallery = :1", gallery )
photos = q.fetch(20)
for photo in photos :
print("\tphoto: " + photo.getUrl('original'))
或者从头开始重新摄取所有数据(尽管我想即使只是重新摄取单个画廊也可以)。
有谁对可能造成这种情况的原因有任何想法吗?任何帮助,将不胜感激。
Notes:
- 这是在开发环境中。我还没有达到值得在真实服务器上将其注册为网络应用程序的程度。
- 奇怪的是,我最近问了一个关于如何如何列出父节点中的子节点 https://stackoverflow.com/questions/6232092/gae-models-how-to-list-child-nodes-in-parent在 GAE 中...因为我真的希望信息存在于父模型定义中。讽刺的是,(显然)父母缺乏这些信息导致了现在的问题