nodes: 0, module; 1, function_definition; 2, function_name:filter; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, dictionary_splat_pattern; 9, expression_statement; 10, with_statement; 11, identifier:order_by; 12, None; 13, identifier:limit; 14, integer:0; 15, identifier:kwargs; 16, comment:"""
              Fetch a list of instances.
  
              :param order_by: column on which to order the results. \
              To change the sort, prepend with < or >.
              :param limit: How many rows to fetch.
              :param kwargs: keyword args on which to filter, column=value
  
          """; 17, with_clause; 18, block; 19, with_item; 20, if_statement; 21, try_statement; 22, as_pattern; 23, comparison_operator:len(kwargs) == 0; 24, block; 25, block; 26, except_clause; 27, except_clause; 28, else_clause; 29, call; 30, as_pattern_target; 31, call; 32, integer:0; 33, raise_statement; 34, expression_statement; 35, expression_statement; 36, if_statement; 37, if_statement; 38, expression_statement; 39, expression_statement; 40, as_pattern; 41, block; 42, as_pattern; 43, block; 44, block; 45, identifier:rconnect; 46, argument_list; 47, identifier:conn; 48, identifier:len; 49, argument_list; 50, identifier:ValueError; 51, assignment; 52, assignment; 53, comparison_operator:order_by is not None; 54, block; 55, comparison_operator:limit > 0; 56, block; 57, call; 58, assignment; 59, identifier:ReqlOpFailedError; 60, as_pattern_target; 61, expression_statement; 62, raise_statement; 63, identifier:Exception; 64, as_pattern_target; 65, expression_statement; 66, raise_statement; 67, expression_statement; 68, return_statement; 69, identifier:kwargs; 70, identifier:query; 71, call; 72, identifier:query; 73, call; 74, identifier:order_by; 75, None; 76, expression_statement; 77, identifier:limit; 78, integer:0; 79, expression_statement; 80, attribute; 81, argument_list; 82, identifier:rv; 83, call; 84, identifier:e; 85, call; 86, identifier:e; 87, call; 88, assignment; 89, identifier:data; 90, attribute; 91, argument_list; 92, attribute; 93, argument_list; 94, assignment; 95, assignment; 96, identifier:log; 97, identifier:debug; 98, identifier:query; 99, attribute; 100, argument_list; 101, attribute; 102, argument_list; 103, attribute; 104, argument_list; 105, identifier:data; 106, list_comprehension; 107, identifier:self; 108, identifier:_base; 109, identifier:query; 110, identifier:filter; 111, identifier:kwargs; 112, identifier:query; 113, call; 114, identifier:query; 115, call; 116, identifier:query; 117, identifier:run; 118, identifier:conn; 119, identifier:log; 120, identifier:warn; 121, identifier:e; 122, identifier:log; 123, identifier:warn; 124, identifier:e; 125, call; 126, for_in_clause; 127, attribute; 128, argument_list; 129, attribute; 130, argument_list; 131, attribute; 132, argument_list; 133, identifier:_; 134, identifier:rv; 135, identifier:self; 136, identifier:_order_by; 137, identifier:query; 138, identifier:order_by; 139, identifier:self; 140, identifier:_limit; 141, identifier:query; 142, identifier:limit; 143, identifier:self; 144, identifier:_model; 145, identifier:_
code: def filter(self, order_by=None, limit=0, **kwargs):
          """
              Fetch a list of instances.
  
              :param order_by: column on which to order the results. \
              To change the sort, prepend with < or >.
              :param limit: How many rows to fetch.
              :param kwargs: keyword args on which to filter, column=value
  
          """
          with rconnect() as conn:
              if len(kwargs) == 0:
                  raise ValueError
  
              try:
                  query = self._base()
                  query = query.filter(kwargs)
  
                  if order_by is not None:
                      query = self._order_by(query, order_by)
  
                  if limit > 0:
                      query = self._limit(query, limit)
  
                  log.debug(query)
                  rv = query.run(conn)
  
              except ReqlOpFailedError as e:
                  log.warn(e)
                  raise
              except Exception as e:
                  log.warn(e)
                  raise
              else:
                  data = [self._model(_) for _ in rv]
                  return data