Bulkloading empty db.ListProperty fields

41 views
Skip to first unread message

Justin

unread,
Dec 30, 2010, 2:32:02 PM12/30/10
to Google App Engine
I have a csv sheet I need to bulkload into AppEngine.

One of the fields is a list of integers of the form (eg) "1,2,3"; the
list can be empty.

I'm using the following import_transform function (where fn=int):

def parse_array(fn):
def wrapper(value):
return [fn(seg) for seg in re.split("\\,", value) if not
seg=='']
return wrapper

This barfs on bulkloading -

>> BadValueError: May not use the empty list as a property value; property myarray is [].

OK, try again -

def parse_array(fn):
def wrapper(value):
if value == '' or value is None or value == []:
return None
return [fn(seg) for seg in re.split("\\,", value)]
return wrapper

This bulkloads fine; but if I try to load an entity with an empty list
field I get the following -

>> BadValueError: Property myarray must be a list

Can anyone suggest how empty db.ListProperty fields should be
initialised from bulkloader ?

Thanks.

Brendan

unread,
Jan 18, 2011, 3:39:25 PM1/18/11
to Google App Engine
This stumped me for a while recently. I discovered that it was
reported as a bug back in August: http://code.google.com/p/googleappengine/issues/detail?id=3646

On the bug page I included a workaround I found, which is just to
bypass the empty validation check for list types. For redundancy, here
it is again.

As of version 1.4.1, line 1313 of
google.appengine.api.datastore_types.py reads:

if not values:

Change that to:

if not values_type is list and not values:

And you should be good to go. Hope that helps.
Reply all
Reply to author
Forward
0 new messages