在 App Engine 批量上传器 yaml 中使用 post_import_function
我正在尝试使用bulkuploader 将一些数据上传到我的App Engine 数据存储区。对于我的一种实体类型,我有一个属性是从另一个属性计算出来的,因此我真的很想在导入每个实体以进行此计算时对每个实体进行一些后处理。我不断看到对 post_import_function 转换标签的简短提及,但没有真正全面的文档或示例。
现在,我只是尝试做一个简单的测试,以使我的 post_import_function 正常工作。
我的实体模型:
class TestEntity(db.Model):
location = db.GeoPtProperty()
cells = db.StringListProperty() # Computed from location
我的bulkloader.yaml文件的相关部分如下所示:
- kind: TestEntity
[... connector info ...]
property_map:
[... transform info for __key__ and location here ...]
post_import_function: post_transform.post_process_testentity
我的post_process_testentity函数:
def post_process_testentity(input_dict, entity_instance, bulkload_state):
entity_instance.cells = [u'Hello there!']
return entity_instance
当我使用所有这些东西进行数据上传时,我没有收到任何错误(并且我知道正在输入post_process_testentity,因为我'在其中添加了一些正确运行的打印语句)。关于上传的一切都有效,除了我的后处理功能完全没有效果。当我使用数据查看器时,我的数据存储中没有“你好!”。
有人可以帮我一下吗?谢谢你!
I'm trying to upload some data to my App Engine datastore using the bulkuploader. For one of my entity types, I have one property that is calculated from another, so I'd really like to do some post-processing on each entity as it's imported to do this calculation. I keep seeing brief mentions of the post_import_function transform tag, but no real comprehensive documentation or examples.
For now, I'm just trying to do a simple test just to get my post_import_function to work.
My entity model:
class TestEntity(db.Model):
location = db.GeoPtProperty()
cells = db.StringListProperty() # Computed from location
The relevant part of my bulkloader.yaml file looks like this:
- kind: TestEntity
[... connector info ...]
property_map:
[... transform info for __key__ and location here ...]
post_import_function: post_transform.post_process_testentity
And my post_process_testentity function:
def post_process_testentity(input_dict, entity_instance, bulkload_state):
entity_instance.cells = [u'Hello there!']
return entity_instance
When I do a data upload with all this stuff, I get no errors (and I know that post_process_testentity is being entered, because I've added a few print statements inside it that ran correctly). Everything about the upload works, except my post processing function has absolutely no effect. There are no "Hello there!"s in my datastore when I use the data viewer.
Could someone help me out a bit? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果其他人也遇到类似的问题,我可以按照上述方法进行测试。看起来后处理函数中的
entity_instance
实际上是google.appengine.api.datastore.Entity
类型,它是dict
的子类。因此,对 post_process_testentity 函数的修改起作用了:但是,我只是通过打印各种调试消息才发现了这一点。如果这些东西被记录在某处,那就太好了。有谁知道我在哪里可以找到此类文档?
In case others are having similar problems, I got my test as described above to work. It seems that
entity_instance
in the post processing function is actually of typegoogle.appengine.api.datastore.Entity
, which is a subclass ofdict
. So, this modification to the post_process_testentity function worked:However, I only figured this out through playing around with printing various debugging messages. It would be great if this stuff was documented somewhere. Does anyone know where I can find such documentation?