Google App Engine - ReferenceProperty() 给出错误 - 通用参考 - Polymodel
给定 Google App Engine 中的 Polymodel,就像这样:
from google.appengine.ext import db
from google.appengine.ext.db import polymodel
class Base(polymodel.PolyModel):
def add_to_referer(self):
Referer(target=self).put()
class Referer(db.Model):
target = db.ReferenceProperty()
@classmethod
def who_referred(cls):
for referer in Referer.all():
obj = referer.target
最后一行给出了这样的错误:
No implementation for kind 'Base'
Traceback 就像这样:
>>> object = referer.target
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in __get__:2804
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in get:1179
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in class_for_kind:220
有人知道这里发生了什么吗?显然,预期的行为是不抛出任何错误。
Base 和 Referer 位于不同的文件中(并且未导入),这可能是相关的。
这个问题可能与Python装饰一个类以更改父级有关对象类型,这是一个仍然潜伏在我脑海中的问题。
感谢您的阅读。
Given a Polymodel in Google App Engine, likeso:
from google.appengine.ext import db
from google.appengine.ext.db import polymodel
class Base(polymodel.PolyModel):
def add_to_referer(self):
Referer(target=self).put()
class Referer(db.Model):
target = db.ReferenceProperty()
@classmethod
def who_referred(cls):
for referer in Referer.all():
obj = referer.target
This last line is giving an error likeso:
No implementation for kind 'Base'
Traceback is likeso:
>>> object = referer.target
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in __get__:2804
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in get:1179
/usr/local/google_appengine/google/appengine/ext/db/__init__.py in class_for_kind:220
Does anyone have any idea what's going on here? The expected behavior would be, obviously, that no error be thrown.
It may be relevant that Base and Referer are in separate files (and not imported).
This problem may be somewhat related to Python decorate a class to change parent object type, which is a question which still lurks in the back of my mind.
Thank you for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊。我发帖后立即回答:
带有Referer的文件需要导入Base。
也许其他人会遇到这个怪癖,所以我将保留这个问题。
Ah. I answered this immediately after I posted:
The file with Referer needs to import Base.
Perhaps someone else will happen upon this quirk, so I'll leave this question open.