code: def get_query(query_id, session, retry_count=5):
      
      query = None
      attempt = 0
      while not query and attempt < retry_count:
          try:
              query = session.query(Query).filter_by(id=query_id).one()
          except Exception:
              attempt += 1
              logging.error(
                  'Query with id `{}` could not be retrieved'.format(query_id))
              stats_logger.incr('error_attempting_orm_query_' + str(attempt))
              logging.error('Sleeping for a sec before retrying...')
              sleep(1)
      if not query:
          stats_logger.incr('error_failed_at_getting_orm_query')
          raise SqlLabException('Failed at getting query')
      return query
docs: attemps to get the query and retry if it cannot