Cannot store empty list to dynamic property
class Mo(db.Expando)
pass
def newFunction
mo = Mo(key_name='1')
mo.list_of_stuff = [] # <--Error
After executing the last statement, I get the error:
Cannot store empty list to dynamic property list_of_stuff
How do I store an empty list to a dynamic property in python for google app engine?
You can’t, because it’s an invalid concept. Datastore entities are stored as a set of key/value pairs. When you store a list of any kind, it’s internally represented as multiple pairs with the same key and different values, rather than one key with a list of values.
Storing an empty list is thus equivalent to not storing anything at all. You just have zero instances of that property inside your entity. If you want to represent an empty list, leave the property unset. If you need to differentiate between an unset property and the concept of an empty list, fill the dynamic property with some other non-empty value, like
NoneorFalse.