我在谷歌应用引擎数据存储中遇到了一个与实体关系非常奇怪的问题。我正在研究Python / GAE webapp(学习练习),可以在sourceforge找到完整的代码。
现在这就是怪异部分的来源...... 如果我更改了一个文件(我测试过的任何文件),甚至只是更新文件的时间戳(即重新加载)。 ..画廊的“.photos”属性开始失败。例如,如果我尝试加载page for the "flowers" gallery:
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'
我可以重新启动webapp,我可以重新启动应用程序启动器,然后启动webapp。无论如何,问题仍然存在。我似乎需要强制数据存储区以某种方式“记住”连接
# 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'))
或者从头开始重新摄取所有数据(虽然我想甚至只需重新摄取一个图库就可以了)。
是否有人对可能导致此问题的原因有任何想法?任何帮助都将不胜感激。
注意:
答案 0 :(得分:2)
所以,经过多次挖掘,我相信我找到了答案......
Photo
类后,会向Gallery based on the collection of ids it has for them
based on the collection of ids it has for them
When it needs the Gallery
class, the app engine reloads the code for it... because it's definition was invalidated by a file being modified
Since it doesn't know it needs the Photo
class, it doesn't load that file, so the "new instance" of the Gallery
class doesn't have the property that should be created for it's collection
{{1}添加一个属性有问题的软件包的文件包含两个文件的依赖项。因此,只要需要其中一个文件,就会加载它们。