Checking SearchIterator for values


I am trying to query my Data Table for rows where the “email_confirmed” column has “True” value and the “apartment” column has “n” value. My goal is to ensure newly registered users don’t try to register the same apartment that another user has already registered, so long as the account is confirmed by email.

I could do this easily enough while I was only checking for dupe “apartments” in a single column, but now I am forced to work with the SearchIterator object because I am doing a more complex query, and the result is not a simple list. My code is below (I commented out the Query operators part):

  def is_apartment_dupe(apartment):
    #y =, apartment=apartment))
    #for x in y:
    #  print(x)
    all_apts = [r['apartment'] for r in]
    if str(apartment) not in all_apts:
      print("no dupe apartment found")
      return None
      return "duplicate apartment found"

How can I check the returned SearchIterator for values? When I tried printing (y), I don’t get an output like a dict, but rather an object, but I couldn’t find documentation about its functions.

Maybe I’m not following what you’re trying to do, but you can nest arbitrarily complex queries. q.all_of, for example, can have other queries inside of it that are more than just equality checks.

A search iterator looks like a list of dictionaries to Python (it isn’t exactly, but it responds to some of the same syntax). So your for x in y loop should have worked fine to pull individual results out. Each of those looks like a dictionary, but isn’t. If you want to print out one for debugging purposes, convert it to an actual dict, e.g. print(dict(x))

1 Like