[英]Google App Engine. TextProperty reset to “”
I run a small video game. 我经营一个小型电子游戏。 Each player has an account model with a variety of properties.
每个玩家都有一个具有各种属性的帐户模型。
I recently added a TextProperty to track player badges. 我最近添加了一个TextProperty来跟踪玩家徽章。 These are just an ASCII character that is appended to the account.badges property as they are awarded.
这些只是被授予时附加到account.badges属性后面的ASCII字符。
Because the properly is new, most account models don't have this property. 因为适当的是新的,所以大多数帐户模型没有此属性。 In about 3 places throughout the site I have some code that looks like this
在整个站点的大约3个地方,我有一些看起来像这样的代码
if not player.badges:
player.badges = ""
player.badges += "A"
player.put_memcache()
player.put()
For some reason, one of the players badges keeps getting reset to "" (empty string). 由于某些原因,其中一个玩家徽章会不断重置为“”(空字符串)。 I can't for the life of me work out how or why.
我无法为自己的生活弄清楚如何或为什么。
I've not worked with TextProperties before. 我以前没有使用过TextProperties。 Is there some strange behaviour I don't understand?
有一些我不理解的奇怪行为吗?
Do TextProperties not play nice with the memcache? TextProperties不能与Memcache配合使用吗?
The account is not getting reset to some old state because other properties seem to be storing values correctly. 该帐户未重置为某些旧状态,因为其他属性似乎正确存储了值。 Its just this one TextProperty.
它就是这个TextProperty。
Anyhow, I'm confused and would appreciated some fresh ideas that would help me track down the issue. 无论如何,我很困惑,希望能有一些新的想法可以帮助我解决问题。
Question Answers 问题答案
The badges propery is just defined like this 徽章属性就是这样定义的
class Account(db.Model):
badges = db.TextProperty()
email = db.StringProperty()
alias = db.StringProperty()
avatar = db.IntegerProperty()
put_memchche is just a wrapper around memcache set. put_memchche只是memcache集的包装器。
def put_memchche(self):
memcache.set("account" + self.key().name(), self)
AFAIK, text is similar to string, the difference is just text can contain more character and cannot be indexed. AFAIK,文本类似于字符串,不同之处在于文本可以包含更多字符且无法编制索引。 If you specify the default to "" I think you do not need the if part.
如果将默认值指定为“”,我认为您不需要if部分。 Is it only happen for one player?
难道只有一个玩家会发生? Are you sure on runtime it hits the player.badges += 'A'.
您确定在运行时会击中玩家。徽章+ ='A'。 It would be easier to debug if you provide more code, based on your example, I don't see a problem why badges do not changed.
如果您提供更多代码,则调试起来会更容易,根据您的示例,我看不出徽章没有更改的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.