在App Engine bulkuploader yaml中使用post_import_function [英] Using post_import_function in App Engine bulkuploader yaml
问题描述
我试图使用bulkuploader将一些数据上传到我的App Engine数据存储。对于我的一个实体类型,我有一个属性是从另一个属性中计算出来的,所以我真的很想对每个实体做一些后处理,因为它会导入以执行此计算。我一直看到post_import_function变量标签的简短提及,但没有真正全面的文档或示例。
现在,我只是试图做一个简单的测试,我的实体模型:
class TestEntity (db.Model):
location = db.GeoPtProperty()
cells = db.StringListProperty()#从位置计算
我的bulkloader.yaml文件的相关部分如下所示:
- kind :TestEntity
[...连接器信息...]
property_map:
[...此处__key__和位置的变换信息...]
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!']
ret urn entity_instance
当我用这些东西做数据上传时,我没有错误(我知道该post_process_testentity正在输入,因为我已经在其中添加了一些正确运行的打印语句)。关于上传的一切工作,除了我的后处理功能是完全没有影响。当我使用数据查看器时,数据存储区中没有Hello there!。
有人可以帮我一下吗?谢谢!
如果其他人遇到类似问题,我按照上述方法进行了测试。看起来后处理函数中的 entity_instance
实际上是类型 google.appengine.api.datastore.Entity
,它是 dict
的子类。因此,对post_process_testentity函数的这种修改是有效的:
$ p $ def $ post_process_testentity(input_dict,entity_instance,bulkload_state):
entity_instance [ 'cells'] = [u'Hello there!']
return entity_instance
然而,我只是通过打印各种调试消息来解决这个问题。如果这个东西被记录在某个地方,那将会很棒。有谁知道我在哪里可以找到这样的文件?
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!
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 type google.appengine.api.datastore.Entity
, which is a subclass of dict
. So, this modification to the post_process_testentity function worked:
def post_process_testentity(input_dict, entity_instance, bulkload_state):
entity_instance['cells'] = [u'Hello there!']
return entity_instance
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?
这篇关于在App Engine bulkuploader yaml中使用post_import_function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!