GAE:通过ListProperty获取实体时的KindError [英] GAE: KindError when getting entities via ListProperty

查看:89
本文介绍了GAE:通过ListProperty获取实体时的KindError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ListProperty存储候选实体键的Contest实体。这里有一些细节:

$ $ p $ class Contest(db.Model):
candidates = db.ListProperty(db.Key )
$ b $ def create_candidate_objects(self):
put_list = []
for n,枚举中的名称(self.tmp_candidates):
put_list.append(Candidate(parent = self,name = name))
keys = db.put(put_list)
self.candidates = keys
self.put()

class Candidate(db .Model):
name = db.StringProperty(required = True)

这个查询:

  c = models.Candidate.all()。ancestor(contest).fetch(2)

一切正常。



但是当我查询使用ListProperty像这样:

  c = db.get(contest.candidates)

我得到错误

  KindError:No类型'候选'的实现

你能帮我理解为什么最后一个查询不起作用吗?我已经将Candidate类导入到正在执行查询的模块中。



更新:请注意,他在开发服务器上以防万一。 p>

UPDATE2:



正如Nick所建议的那样:

  c2 = models.Candidate.get(contest.candidates)

但是这不起作用(引发KindError):

  from models import Candidate 
c = db.get比赛参赛者)

UPDATE3:

有问题的行出现在测试代码中,所以我无法在生产服务器上尝试这种特殊故障。我在其他地方使用了完全相同的产品线,并且它在开发和生产服务器上都能正常工作。



Nick询问了进口产品,我在测试代码中这样做:

  sys.path.append(/ usr / local / google_appengine / lib / simplejson)
导入simplejson as json

但其他所有内容都是典型的。

您很可能在另一个未导入的模块中定义了 Candidate Candidate 定义在哪里?您是否在调用 db.get 时导入了它所在的模块?调用 Candidate.get(key_list)应该可以工作,因为它会强制你在调用它时有一个有效的 Candidate

I have a Contest entity which uses a ListProperty to store keys of Candidate entities. Here are some details:

class Contest(db.Model):
    candidates = db.ListProperty(db.Key)

    def create_candidate_objects(self):
        put_list = []
        for n, name in enumerate(self.tmp_candidates):
            put_list.append(Candidate(parent = self, name = name))
        keys = db.put(put_list)
        self.candidates = keys
        self.put()

class Candidate(db.Model):
    name = db.StringProperty(required = True)

When I do this query:

c = models.Candidate.all().ancestor(contest).fetch(2)

Everything works fine.

But when I do a query using the ListProperty like this:

c = db.get(contest.candidates)

I get the error

KindError: No implementation for kind 'Candidate'

Can you help me understand why the last query does not work? I have imported the Candidate class into the module that is doing the query.

UPDATE: Note that his is on the dev server in case that might make a difference.

UPDATE2:

As suggested by Nick, this works:

c2 = models.Candidate.get(contest.candidates)

but this does not work (raises KindError):

from models import Candidate
c = db.get(contest.candidates)

UPDATE3:

The offending line occurs in test code so I can't try this particular failure on the production server. I have used the exact same line elsewhere and it does work on both the dev and production servers.

Nick asked about imports, and I am doing this in my test code:

sys.path.append("/usr/local/google_appengine/lib/simplejson")
import simplejson as json

but everything else is just typical.

解决方案

Most likely you're defining Candidate in another module you haven't imported. Where is Candidate defined? Have you imported the module it's in when you call db.get? Calling Candidate.get(key_list) should work, since it forces you to have a valid Candidate when you call it.

这篇关于GAE:通过ListProperty获取实体时的KindError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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