2012-02-20 29 views
1

我在App Engine的本地devserver上看到一些奇怪的行爲,同時在查詢上進行過濾。App Engine devserver查詢過濾器不工作

我已經實現了這個Sharded Counter。

http://code.google.com/appengine/articles/sharding_counters.html

這是我所看到的:

  1. 我增加計數器,併成功創建了計數器實體和Count獲取,因爲它應該更新。
  2. 此後立即當我調用get_count()時,它返回剛剛創建的GeneralCounterShard實體的計數
  3. 稍後,當我調用getCount()時,它不返回任何內容。

調試後,我注意到查詢應該匹配GeneralCounterShard實體,我要計數,與提供的名稱不匹配。

def get_count(name):  
"""Retrieve the value for a given sharded counter. 
Parameters:  name - The name of the counter """ 
total = memcache.get(name) 
if total is None: 
    total = 0 
    for counter in GeneralCounterShard.all().filter('name = ', name): 
     total += counter.count 
     memcache.add(name, total, 60) 
return total 

所以在代碼中的過濾器上面並沒有同時有與數據庫提供的名稱 GeneralCounterShard實體匹配任何內容。

我必須說我是App Engine和Python的新手,但我不明白爲什麼這個工作片刻,然後它不再。實體仍在數據庫中。

這可能是某種錯誤,或者我錯過了什麼?

謝謝!

+0

'name'區分大小寫。你在'getCount()'的調用中是否確實使用了相同的外殼? – 2012-02-20 17:40:46

+0

我仍然不明白爲什麼會發生這種情況。但是當我將代碼上傳到生產服務器時,一切都正常運行。代碼沒有錯,但它是與開發服務器或我不明白的開發服務器的東西...無所謂了,只是現在使用產品實例... – Quint 2012-03-08 08:31:46

回答

1

在這個片段中:.filter('name =',name)我認爲你需要刪除=之後的空格。