Question

How do I know if the results of my query either using the Query interface or the GqlQuery interface returned zero results? Would using .get() on zero results produce an error? If yes, what's the best way to handle it?

Was it helpful?

Solution

when doing a get() if there are no results you will have an object containing None

I normally do

result = query.get()
if result is None:
  #do the following

or if you want to check that its not none then

if result is not None:
  #do the following

OTHER TIPS

if a query returns no results, fetch() returns an empty list [] and get() returns None

in either case you can use the following:

if result:
    #handle the result
else:
    #no results were returned
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top