【发布时间】:2012-05-04 14:00:08
【问题描述】:
我已经收集了数据,它不是特别干净的数据,并且已经批量上传到 DataStore。但是,当尝试简单地遍历所有记录时,我遇到了以下问题。此时我不太关心验证,因为我想做的只是执行批量操作,但 GAE 似乎甚至不允许我遍历数据记录。我想深入了解这一点。据我所知,所有记录都有该国家/地区的现场数据,我可以切换验证,但有人可以解释为什么会发生这种情况并且 GAE 很敏感。谢谢
result = Company.all()
my_count = result.count()
if result:
for r in result:
self.response.out.write("hello")
数据模型具有以下属性:
class Company(db.Model):
companyurl = db.LinkProperty(required=True)
companyname = db.StringProperty(required=True)
companydesc = db.TextProperty(required=True)
companyaddress = db.PostalAddressProperty(required=False)
companypostcode = db.StringProperty(required=False)
companyemail = db.EmailProperty(required=True)
companycountry = db.StringProperty(required=True)
错误信息如下
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/XXX/1.358667163009710608/showcompanies.py", line 99, in get
for r in result:
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 2312, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1441, in from_entity
return cls(None, _from_entity=entity, **entity_values)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 973, in __init__
prop.__set__(self, value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 613, in __set__
value = self.validate(value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 2815, in validate
value = super(StringProperty, self).validate(value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 640, in validate
raise BadValueError('Property %s is required' % self.name)
BadValueError: Property companycountry is required
【问题讨论】:
-
这个错误什么时候出现?不要认为当你遍历实体并写出你好时会发生这种情况......这看起来像你正在尝试保存/放置一个实体并且你错过了 companycountry 值。
-
我上面的代码明智的是骨架代码。我正在编辑一些值,但即使只是循环记录我也会遇到同样的问题......为什么我很惊讶。在执行 put 的那部分代码中没有任何地方。
-
引发该错误的确切代码是什么。显然,有一个实体是在没有该特定属性的情况下构建的。请发布整个回溯,不仅是最后 3 行...
-
@aschmid00,给你:
-
好的,所以它实际上看起来像它的验证实体,即使在迭代查询时也是如此。您是否尝试在迭代它们之前获取一批?还是删除属性中的 required=True 参数?
标签: google-app-engine gql