Empty list in App Engine Datastore: Java vs Python Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Empty list in App Engine Datastore: Java vs Python without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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!

Answer

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

uvw = db.ListProperty(int, default=[])
We are here to answer your question about Empty list in App Engine Datastore: Java vs Python - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji