How can I use none_if_empty with create_deep_key?

大城市里の小女人 提交于 2019-12-11 10:53:48

问题


I was looking at Where are the reference pages of the Google App Engine bulkloader transform? and figured out most of my bulkloader.yaml configuration with the exception of one case.

One of my Kinds 'Product' has a property called site. If present this is a deep key for a Customer Kind and a Site kind. Now the problem I am having is with the non_if_empty. In the below case it will not ever create the deep key. It always comes back none. If I remove the transform.none_if_empty it will fail as my input file has empty entires for some of these values. How can I make this work? How can I use none_if_empty with create_deep_key

- property: site
  external_name: site
  export_transform: transform.key_id_or_name_as_string
  import_transform: transform.none_if_empty(transform.create_deep_key(('Customer', 'siteCustomer', True),
                                                ('Site', 'siteId', True)))

  export: 
   - external_name: siteCustomer
     export_transform: transform.key_id_or_name_as_string_n(0)
   - external_name: siteId
     export_transform: transform.key_id_or_name_as_string_n(1)

Product Bulkloader File Example
name,siteCustomer,siteId
first,,
second,1,1

回答1:


That should be

import_transform: transform.none_if_empty(transform.create_deep_key(
    ('Customer','siteCustomer', True),
    ('Site', transform.CURRENT_PROPERTY, True)))

Essentially, refer to the current property's import value as transform.CURRENT_PROPERTY.




回答2:


So I still don't know what I am missing here but my work around is thus:

from google.appengine.ext.bulkload import transform

def create_deep_key(*path_info): f = transform.create_deep_key(*path_info)

def create_deep_key_lambda(value, bulkload_state):

    try:
        return f(value, bulkload_state)
    except:
        return None

return create_deep_key_lambda


来源:https://stackoverflow.com/questions/11873895/how-can-i-use-none-if-empty-with-create-deep-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!