nodes: 0, module; 1, function_definition; 2, function_name:sort_query; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, identifier:sort_info; 8, expression_statement; 9, for_statement; 10, return_statement; 11, comment:"""Sort query according to jsonapi 1.0
  
          :param Query query: sqlalchemy query to sort
          :param list sort_info: sort information
          :return Query: the sorted query
          """; 12, identifier:sort_opt; 13, identifier:sort_info; 14, block; 15, identifier:query; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, assignment; 20, not_operator; 21, block; 22, assignment; 23, identifier:field; 24, subscript; 25, call; 26, raise_statement; 27, identifier:query; 28, call; 29, identifier:sort_opt; 30, string; 31, identifier:hasattr; 32, argument_list; 33, call; 34, attribute; 35, argument_list; 36, string_content:field; 37, attribute; 38, identifier:field; 39, identifier:InvalidSort; 40, argument_list; 41, identifier:query; 42, identifier:order_by; 43, call; 44, identifier:self; 45, identifier:model; 46, call; 47, call; 48, argument_list; 49, attribute; 50, argument_list; 51, identifier:getattr; 52, argument_list; 53, string:"{} has no attribute {}"; 54, identifier:format; 55, attribute; 56, identifier:field; 57, call; 58, subscript; 59, attribute; 60, identifier:__name__; 61, identifier:getattr; 62, argument_list; 63, identifier:sort_opt; 64, string; 65, identifier:self; 66, identifier:model; 67, attribute; 68, identifier:field; 69, string_content:order; 70, identifier:self; 71, identifier:model
code: def sort_query(self, query, sort_info):
          """Sort query according to jsonapi 1.0
  
          :param Query query: sqlalchemy query to sort
          :param list sort_info: sort information
          :return Query: the sorted query
          """
          for sort_opt in sort_info:
              field = sort_opt['field']
              if not hasattr(self.model, field):
                  raise InvalidSort("{} has no attribute {}".format(self.model.__name__, field))
              query = query.order_by(getattr(getattr(self.model, field), sort_opt['order'])())
          return query