A: 

The documentation on how indexes are stored says:

For multi-valued properties, such as ListProperty and StringListProperty, each value has its own index row, so using multi-valued properties does result in more indexing overhead.

So for each item in your list property, there is a row in the index.

My expectation would be that if there are no items in the list property, then there would be no rows in the index. So it wouldn't be possible to use the index to retrieve entities with an empty list.

One solution would be to add another property (eg hasbranches = db.BooleanProperty()), which you maintain when you add or remove branches. Then you will be able to filter for hasbranches = False.

Saxon Druce
+1  A: 

You can't do this with a filter: as Saxon says, there's no index row matching what you want to retrieve, and so no way to retrieve it.

One simple alternative is to store another property that contains the number of elements in the list, and filter on that. aetycoon is a library that contains computed properties that may help with that:

class TreeNode(db.Model):
  name = db.StringProperty()
  branches = db.ListProperty(db.Key)
  branch_count = aetycoon.DerivedProperty(lambda self: len(self.branches))
Nick Johnson