Python 无法解析ReferenceProperty--应用程序引擎

Python 无法解析ReferenceProperty--应用程序引擎,python,google-app-engine,python-2.7,referenceproperty,Python,Google App Engine,Python 2.7,Referenceproperty,我遇到了一个错误,无法找出其根本原因。错误如下:“未能解析ReferenceProperty:[u'StatusLog',STATUSLOGSID]”。这种错误只会偶尔发生,大约每天发生一到两次。生成此错误的脚本的成功率高于失败率。这个错误最奇怪的一点是,它无法解析引用属性,这种情况永远不会发生(关于这种情况),因为我的webapp从未删除被引用的实体。此外,我没有生成被引用的密钥,谷歌应用程序引擎是。下面列出了相关代码 GAE交易: def updateStatus(key): hbo

我遇到了一个错误,无法找出其根本原因。错误如下:“未能解析ReferenceProperty:[u'StatusLog',STATUSLOGSID]”。这种错误只会偶尔发生,大约每天发生一到两次。生成此错误的脚本的成功率高于失败率。这个错误最奇怪的一点是,它无法解析引用属性,这种情况永远不会发生(关于这种情况),因为我的webapp从未删除被引用的实体。此外,我没有生成被引用的密钥,谷歌应用程序引擎是。下面列出了相关代码

GAE交易:

def updateStatus(key):
    hbo = HBO.get(key)
    hbo.updateStatus()
    hbo.put()

class HBOCRON(webapp2.RequestHandler):
    def get(self):
        keys = db.Query(HBO, keys_only = True).filter("inactive = ", False)
        XG_ON = db.create_transaction_options(xg=True)
        for key in keys: db.run_in_transaction_options(XG_ON, updateStatus, key)

app = webapp2.WSGIApplication([('/cron/hbo', HBOCRON)],debug=True)
其他两个相关功能

def logStatus(self):
    self.status = StatusLog(
        hbo = self,
        prev = self.status,
        date = datetime.datetime.now(),
        on = self.online(),
        up = self.upToDate(),
        dns = self.DNS_update_needed,
        dis = self.manually_disabled).put()

def updateStatus(self):
    status = self.status
    if status is None \
        or status.on != self.online() \
        or status.up != self.upToDate() \
        or status.dns != self.DNS_update_needed:
        self.logStatus()
        self.flagged = True
    elif status.dis != self.manually_disabled:
        self.logStatus()
回溯:

感谢您提供的任何见解/帮助/答案/建议


当您尝试解析引用属性(通过取消引用它-例如,(MyModel.MyReferenceProp.foo),并且被引用的属性不再存在时,就会发生这种情况,因为它已被删除


您需要修改代码,以便在取消引用可能已删除的实体时捕获此异常,并对其进行适当处理。

请提供日志中的回溯以及实际取消引用ReferenceProperty的代码片段。我已将完整的回溯添加到我的SO帖子中。感谢您创建如此精彩的回溯正在编写脚本语言并活跃于Python社区。你好,Nick,感谢您回复我的帖子。我知道当您尝试解析引用属性时会发生这种情况;但是,我和我的同事从未删除任何StatusLog实体。因此,我们很好奇,当实体被删除的实体永远不会被修改或删除。@JustinPapez在这种情况下,您应该捕获异常,并检查相关实体以查看其错误所在。是的,这就是我们目前正在做的事情;但它似乎有点“黑客化”。它也发生在同一类的不同实体上。谢谢你的帮助。@JustinPapez,这是调试。调试经常是黑客行为。你学到了什么?不幸的是,还没有。即使在进一步检查代码和进一步调试之后,问题仍然时不时地发生。
ReferenceProperty failed to be resolved: [u'StatusLog', 248327L]
Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~hs-hbo/1.357660268729453201/api/hbo/getCheckin.py", line 88, in post
    (hbo, data) = db.run_in_transaction_options(XG_ON, checkinTransaction, self.request)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 2476, in RunInTransactionOptions
    ok, result = _DoOneTry(new_connection, function, args, kwargs)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 2498, in _DoOneTry
    result = function(*args, **kwargs)
  File "/base/data/home/apps/s~hs-hbo/1.357660268729453201/api/hbo/getCheckin.py", line 33, in checkinTransaction
    hbo.updateStatus()
  File "/base/data/home/apps/s~hs-hbo/1.357660268729453201/shared/datastore.py", line 116, in updateStatus
    return self.logStatus()
  File "/base/data/home/apps/s~hs-hbo/1.357660268729453201/shared/datastore.py", line 102, in logStatus
    prev = self.status,
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 3597, in __get__
    reference_id.to_path())
ReferencePropertyResolveError: ReferenceProperty failed to be resolved: [u'StatusLog', 248327L]