1

我在 Google App Engine SDK v1.8.2.1 中遇到了一个奇怪的问题。SDK 似乎对我检索属性值的方式存在问题。实体如下所示:

class userDB(EndpointsModel):
    userID = ndb.StringProperty(required=True, indexed=True)
    name = ndb.StringProperty(required=True, indexed=True)
    update = ndb.DateTimeProperty(indexed=True)
    orgs = ndb.StructuredProperty(providers, repeated=True, indexed=True)
    system = ndb.StructuredProperty(system, repeated=True, indexed=True)
    comp = ndb.StructuredProperty(comp, repeated=True, indexed=True)

从数据存储查看器:

orgs.value (list) [u'comp', u'system']

我的 cron 工作代码:

class CronRefresh(webapp2.RequestHandler):
    def get(self):  
        for user in userDB.query().fetch():
            for org in user.orgs:
                provider.addItems(user.key, org.value)

当我将 org.value 打印到控制台日志时没有问题,但是当我尝试将其传递给函数时,它会引发以下错误。

INFO     2013-07-29 17:28:30,980 module.py:595] default: "POST / HTTP/1.1" 200 594
ERROR    2013-07-29 21:28:37,374 webapp2.py:1552] '_BaseValue' object has no attribute 'value'

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__

    return handler.dispatch()

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch

    return self.handle_exception(e, self.app.debug)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch

    return method(*args, **kwargs)

  File "E:\main.py", line 74, in get

    provider.addItems(user.key, org.value)

AttributeError: '_BaseValue' object has no attribute 'value'

INFO     2013-07-29 17:28:37,382 module.py:595] default: "GET /cron/refresh HTTP/1.1" 500 114
INFO     2013-07-29 17:28:49,043 module.py:595] default: "GET /cron/refresh HTTP/1.1" 200 -

但是,如果我两次运行 cron 作业,它会顺利进行。有谁看到我做错了什么?这是预期的行为吗?

更新:提供者是我写的一个导入。任何帮助将非常感激。

UPDATE2:添加了 addItems 功能。我已经确认 apple_list 是正确的字典列表。

def addItems(key, X):
user = key.get()
if X == 'apple':
    def add(item):
        newObject = apple(name=item['name'], status=item['status'], obtained=item['obtained'])
        objectList = user.query().fetch()[0].apple
        for object in objectList: 
            if (object.name == item['name'] and (object.status != item['status'] or object.obtained != item['obtained'])):
                logging.debug("If #1 Happened")
                continue
            elif (object.name == item['name'] and object.status == item['status'] and object.obtained == item['obtained']):
                logging.debug("If #2 Happened")
                continue
            else:
                logging.debug("Else Happened")
                continue

    if not user.query().fetch()[0].apple:
        for item in apple_list:
            user.apple.append(apple(name=item['name'], status=item['status'], obtained=item['obtained']))
            user.put()
    else:
        for item in apple_list:
            add(item)
4

1 回答 1

1

显然,user.orgs一直put()到数据库。将其“变异”为 a _BaseValue,如下所述:List items from duplicate StringProperty get mutated to _BaseValue on put

于 2013-08-01T05:07:26.090 回答