1

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
Community
  • 1
  • 1
David Ward
  • 493
  • 3
  • 15

2 Answers2

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.

Sumeet Singh
  • 306
  • 1
  • 4
  • In the case above that's actually not what I want but even still if I use your suggestion I end up with a null key even though the two values are set. The keep key is never created. It's always none. I just can't figure out why. – David Ward Aug 09 '12 at 18:33
  • It's strange too because if I do import_transform: transform.none_if_empty(transform.create_foreign_key('Customer', key_is_id=True)) everything works fine. But if I do the same thing with the create_deep_key function I always get none. – David Ward Aug 09 '12 at 19:33
0

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
David Ward
  • 493
  • 3
  • 15