def optional_one(query):
  """Like calling one() on query, but returns None instead of raising
  NoResultFound.
  """
  results = query.limit(1).all()
  if results:
    return results[0] 
  return None