Search code examples
pythongoogle-app-enginedatetimegoogle-cloud-datastorelistproperty

Time inequality filters on app engine ListProperty fail when chained


I have ListProperty's in an entity that contains two time objects that represent a business' open and closing times for a day of the week:

mon_hours = db.ListProperty(datetime.time)
tue_hours = db.ListProperty(datetime.time)
wed_hours = db.ListProperty(datetime.time)
thu_hours = db.ListProperty(datetime.time)
fri_hours = db.ListProperty(datetime.time)
sat_hours = db.ListProperty(datetime.time)
sun_hours = db.ListProperty(datetime.time)

When I query this entity using the current time AND chain the filters to properly return only records where the list has a time greater and less than, it fails with 0 results:

now = datetime.datetime.now()
q = Place.all()           
q.filter('mon_hours <=', now.time()).filter('mon_hours' >=', now.time())

However, when I remove one of the filters, it returns results, albiet the wrong ones:

now = datetime.datetime.now()
q = Place.all()           
q.filter('mon_hours <=', now.time())

When I manually set the minutes to 00, it works for some reason:

q = Place.all()           
q.filter('mon_hours <=', datetime.datetime(1970,1,1,10,00).time()).filter('mon_hours' >=', datetime.datetime(1970,1,1,10,00).time())

This last query is the desired results but the time needs to be the current time with arbitrary minutes.

WTF?!


Solution

  • My bad. I made the assumption that app engine worked on list properties like mongodb. If two inequality filter are applied to a list property, one value in the list has to match both. The successful results at 00 and 30 minute marks where artifacts of using >=, <= where one value was matching both.

    Doh.