简体   繁体   English

Google App Engine。 TextProperty重置为“”

[英]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.

相关问题 Google App Engine上TextProperty的最大大小是多少 - what is the max size of TextProperty on google app engine Google App Engine TextProperty和UTF-8:何时进行编码/解码 - Google App Engine TextProperty and UTF-8: When to Encode/Decode Python Google App Engine。 两次发送GET请求 - Python Google App Engine. GET Request sent twice Google App Engine。 如何在应用范围内创建常量? - Google App Engine. How to create constant in application scope? 在Google App Engine上顺序插入的事务冲突。 为什么? - Transaction collision for sequential insert on Google App Engine. Why? 使用谷歌应用引擎将文件插入谷歌驱动器。 使用python客户端api - Insert a file to google drive using google app engine. python client api used Python 与 Google App Engine。 AttributeError: 'module' object has no attribute 'HTTPSHandler' 错误信息 - Python with Google App Engine. AttributeError: 'module' object has no attribute 'HTTPSHandler' error message Google App Engine中的自定义属性。 发送到Make_value_from_datastore的值不是保存的类型 - Custom property in Google App Engine. Value sent to Make_value_from_datastore is not of the type saved Google App引擎上的PyDrive。 无法通过StringIO对象设置GoogleDrive对象的内容 - PyDrive on Google App engine. Can't set the content of a GoogleDrive object from a StringIO object App Engine。 每隔一分钟查询一次 - App Engine. Querying Every Other Minute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM