Skip to content Skip to sidebar Skip to footer

NDB Query Builder Doesn't Work As Expected

I have the following query in my application query = cls.query().filter(cls.taskgroup_id == taskgroup_id, cls.availability == True, cls.task_id > min_task_id).order(cls.task_id)

Solution 1:

From Filtering by Property Values (emphasis mine):

query = Account.query(Account.userid >= 40, Account.userid < 50)

[...]

Instead of specifying an entire query filter in a single expression, you may find it more convenient to build it up in steps: for example:

appengine/standard/ndb/queries/snippets.py

query1 = Account.query()  # Retrieve all Account entitites
query2 = query1.filter(Account.userid >= 40)  # Filter on userid >= 40
query3 = query2.filter(Account.userid < 50)  # Filter on userid < 50 too

query3 is equivalent to the query variable from the previous example. Note that query objects are immutable, so the construction of query2 does not affect query1 and the construction of query3 does not affect query1 or query2.

In other words for your example none of the query.filter() statements actually modifies query.

Just assign the results of the statements to local variables and use those instead, just as in the quoted example.


Post a Comment for "NDB Query Builder Doesn't Work As Expected"