Zero Result: Query / GqlQuery

How do I know if the results of my query, either using the Query interface or the GqlQuery interface, returned null results? Does a .get()

null result use an error? If so, what's the best way to handle this?

+2


source to share


2 answers


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

I usually do

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

      



or if you want to check that it is not there, then

if result is not None:
  #do the following

      

+5


source


If the query returns no results, it fetch()

returns an empty list []

and get()

returnsNone

you can use the following anyway:



if result:
    #handle the result
else:
    #no results were returned

      

+2


source







All Articles