Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a record exists in App Engine Datastore

From what I've read, this is how I should check for any records...

    v = PC_Applications.all().filter('column =', value)
if not v:
    return False

But this returns an error!

IndexError: The query returned fewer than 1 results

Any ideas to doing this? I've read that .count() is a bad option. I'm new to Python and App Engine so thank you for any patience!

like image 577
Ryan Avatar asked Apr 08 '11 23:04

Ryan


2 Answers

if not v.get():

From App Engine, Query Class get()

Executes the query, then returns the first result, or None if the query returned no results.

like image 56
hyperslug Avatar answered Nov 02 '22 01:11

hyperslug


This should work:

q = db.Query(PC_Applications, keys_only = True)
if not q.get():
    return false

I think .all().filter('column =', value) is even worse than .count, because it's not doing a keys-only query.

like image 38
Sean Fujiwara Avatar answered Nov 02 '22 01:11

Sean Fujiwara