8

I've had some data being gathered in production for a couple of days with, lets say, the following model:

class Tags(ndb.Model):
    dt_added = ndb.DateTimeProperty(auto_now_add=True)
    s_name   = ndb.StringProperty(required=True, indexed=True)

Imagine I now add a new property to the model:

class Foo(ndb.Model):
    is_valid = ndb.BooleanProperty(default=False)
    some_key = ndb.KeyProperty(repeated=True)

class Tags(ndb.Model):
    dt_added = ndb.DateTimeProperty(auto_now_add=True)
    name     = ndb.StringProperty(required=True, indexed=True)
    new_prop = ndb.StructuredProperty(Foo)

... and gather some more data with this new model.

So now I have a portion of data that has the property new_prop set, and another portion that does not have it set.

My question is: how to I query for the data with the new property new_prop NOT set?

I've tried:

query_tags = Tags.query(Tags.new_prop == None).fetch()

But does not seem to get the data without that property set... Any suggestions? Thanks!

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Michael Gradek
  • 2,628
  • 3
  • 29
  • 35

1 Answers1

6

The Datastore distinguishes between an entity that does not possess a property and one that possesses the property with a null value (None).

It is not possible to query for entities that are specifically lacking a given property. One alternative is to define a fixed (modeled) property with a default value of None, then filter for entities with None as the value of that property.

pgiecek
  • 7,970
  • 4
  • 39
  • 47