getredash/redash · error · ValueError

Queries of type {} can not be processed by redash.

Error message

Queries of type {} can not be processed by redash.

What it means

Raised by SparqlEndpoint.run_query (redash/query_runner/sparql_endpoint.py:127) as ValueError when the parsed SPARQL query type is not SELECT (and not None). Redash can only tabulate SELECT result sets, so ASK, CONSTRUCT, DESCRIBE, and update queries (INSERT/DELETE) are rejected before the request is sent.

Source

Thrown at redash/query_runner/sparql_endpoint.py:127

    @classmethod
    def enabled(cls):
        return enabled

    @classmethod
    def type(cls):
        return "sparql_endpoint"

    def remove_comments(self, string):
        return string[string.index("*/") + 2 :].strip()

    def run_query(self, query, user):
        """send a query to a sparql endpoint"""
        logger.info("about to execute query (user='{}'): {}".format(user, query))
        query_text = self.remove_comments(query)
        query = SparqlQuery(query_text)
        query_type = query.get_query_type()
        if query_type not in ["SELECT", None]:
            raise ValueError("Queries of type {} can not be processed by redash.".format(query_type))

        self._setup_environment()
        try:
            endpoint = self.configuration.get("SPARQL_BASE_URI")
            r = requests.get(
                endpoint,
                params=dict(query=query_text),
                headers=dict(Accept="application/json"),
            )
            data = self._transform_sparql_results(r.text)
        except Exception as error:
            logger.info("Error: {}".format(error))
            try:
                # try to load Problem Details for HTTP API JSON
                details = json.loads(error.response.text)
                error = ""
                if "title" in details:
                    error += details["title"] + ": "

View on GitHub (pinned to ca79fe988d)

Solutions

  1. Rewrite the query as SELECT (e.g. convert ASK to SELECT 1 AS result WHERE {...}, project CONSTRUCT triples via SELECT ?s ?p ?o)
  2. Run SPARQL updates outside Redash with a dedicated tool or HTTP client
  3. Strip leading comments so the type detector sees the real first keyword

Example fix

# before
ASK { ?s a foaf:Person }
# after
SELECT ?s WHERE { ?s a foaf:Person } LIMIT 100
Defensive patterns

Strategy: validation

Validate before calling

qtype = SparqlQuery(remove_comments(query)).get_query_type()
if qtype not in ('SELECT', None):
    return None, 'Only SELECT queries are supported, got {}'.format(qtype)

Type guard

def is_supported_sparql(q: str) -> bool:
    t = SparqlQuery(q).get_query_type()
    return t in ('SELECT', None)

Try / catch

try:
    run_query(query, user)
except ValueError as e:
    return error_response(400, str(e))

Prevention

When it happens

Trigger: Executing an ASK/CONSTRUCT/DESCRIBE query, or a SPARQL UPDATE (INSERT DATA / DELETE WHERE), against the SPARQL endpoint data source; a query whose leading keyword after comment stripping is anything but SELECT.

Common situations: Users pasting full graph-update scripts into Redash; CONSTRUCT queries intended for RDF extraction; commented-out prefixes confusing the naive type detection so a non-SELECT statement is inferred.

Related errors


AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28). Data as JSON: /api/errors/f737fc40a4c0bbb4. Report an issue: GitHub.