我已将列表属性添加到具有大量现有实例的实体模型中。
class MyModel(db.Model):
new_property = db.ListProperty(item_type=str, default=None)
部署到实时环境后,应用程序会在短时间内正常运行,然后在尝试从数据存储区检索记录时开始抛出 BadValueError 错误。
抛出错误的代码只是对数据存储的直接调用:
app_item = db.get(app_item_key)
我正在使用 1.7.5。Python 2.7 运行时。
关于我可以做些什么来防止这种情况的任何想法,或者至少捕获它以便我可以从商店获取数据?
Traceback (most recent call last):
File "/base/data/home/apps/app/4-15.365909351579418812/app.py", line 1739, in app_get
app_item = db.get(app_item_key)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 1533, in get
return get_async(keys, **kwargs).get_result()
File "/python27_runtime/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 604, in get_result
return self.__get_result_hook(self)
File "/python27_runtime/python27_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1459, in __get_hook
entities = rpc.user_data(entities)
File "/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 600, in local_extra_hook
return extra_hook(result)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 1503, in extra_hook
model = cls1.from_entity(entity)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 1438, in from_entity
return cls(None, _from_entity=entity, **entity_values)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 970, in __init__
prop.__set__(self, value)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 614, in __set__
value = self.validate(value)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 3460, in validate
value = super(ListProperty, self).validate(value)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 641, in validate
raise BadValueError('Property %s is required' % self.name)
BadValueError: Property new_property is required
对于以下人员:
根据 Aaron D 的建议,将默认值更改为空列表可以解决此问题,因此:
new_property = db.ListProperty(item_type=str, default=None)
应该读:
new_property = db.ListProperty(item_type=str, default=[])