2012-03-22 38 views
2

我遇到了一個錯誤,我無法找到根本原因。錯誤如下:「ReferenceProperty未能解決:[u'StatusLog',STATUSLOGSID]」。這種錯誤有時會發生,大約每天一次或兩次。產生這種錯誤的腳本比失敗的腳本更成功。關於錯誤的最奇怪的事情是它無法解析引用屬性,而不應該是這種情況(就這種情況而言),因爲被引用的實體永遠不會被我的webapp刪除。此外,我不會生成Google App Engine正在引用的密鑰。下面列出了相關的代碼。ReferenceProperty未能解決 - App Engine

的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() 

回溯:

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] 

感謝您的任何見解/幫助/答案/建議!

+1

請提供來自日誌和實際取消引用的ReferenceProperty的代碼片段的追溯 – 2012-03-23 03:48:00

+0

I已經添加了完整的追溯到我的SO帖子。感謝您創建這樣一個美妙的腳本語言a nd在Python社區中處於活躍狀態。 – 2012-03-23 16:36:27

回答

2

出現這種情況,當你嘗試解決參考屬性(通過取消引用它 - 例如,(MyModel.MyReferenceProp.foo),以及被引用的屬性不再存在 - 因爲它已被刪除

您需要修改代碼才能解決引用可能已被刪除的實體並對其進行適當處理的異常。

+0

嗨,尼克,感謝您回覆我的文章。我知道當你試圖解析一個引用屬性時會發生這種情況;然而,我的同事和我從不刪除任何StatusLog實體。因此,我們很好奇,在被刪除的實體從未被修改或刪除時,它如何解析引用屬性失敗。 – 2012-03-23 16:40:38

+1

@JustinPapez在這種情況下,你應該捕捉異常,並檢查有問題的實體,看看有什麼不對。 – 2012-03-24 07:58:03

+0

是的,這就是我們目前所做的;但它似乎有點「駭人聽聞」。它也發生在同一類別的不同實體上。謝謝你的幫助。 – 2012-03-24 19:35:04

相關問題