Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty list in App Engine Datastore: Java vs Python

I have the following java model class in App Engine:

public class Xyz ... {
    @Persistent
    private Set<Long> uvw;
}

When saving an object Xyz with an empty set uvw in Java, I get a "null" field (as listed in the appengine datastore viewer). When I try to load the same object in Python (through remote_api), as defined by the following python model class:

class Xyz(db.Model):
    uvw = db.ListProperty(int)

I get a "BadValueError: Property uvw is required".

When saving another object of the same class in Python with an empty uvw list, the Datastore viewer prints a "missing" field.

Apparently empty lists storage handling differs between Java and Python and lead to "incompatible" objects.

Thus my question: Is there a way to, either:

  • force Java to store an empty list as a "missing" field,
  • force Python to gracefully accept a "null" list as an empty list when loading the object?

Or any other suggestion on how to handle empty list field in both languages.

Thanks for your answers!

like image 744
Laurent Grégoire Avatar asked Feb 22 '10 14:02

Laurent Grégoire


1 Answers

It should work if you assign a default value to your Python property:

uvw = db.ListProperty(int, default=[])
like image 162
Claude Vedovini Avatar answered Sep 24 '22 05:09

Claude Vedovini