应用程序引擎devserver查询筛选器不工作

2024-03-29 13:15:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我看到appengine的本地devserver在过滤查询时出现了一些奇怪的行为。在

我已经实现了这个碎片计数器。在

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

我看到的是:

  1. 我增加了计数器,成功地创建了counter实体,并按需要更新了计数。在
  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实体时,上面代码中的过滤器不匹配任何内容。在

我必须说,我对appengine和Python还是个新手,但我不明白为什么这一点会起作用,然后就不起作用了。实体仍在数据库中。在

这可能是某种缺陷还是我遗漏了什么?在

谢谢!在


Tags: thename实体数据库forgetcountcounter