Google App Engine - ReferenceProperty() 给出错误 - 通用参考 - Polymodel

发布于 2024-08-06 02:45:50 字数 1101 浏览 6 评论 0原文

给定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-08-13 02:45:50

啊。我发帖后立即回答:

带有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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文