Skip to content

Conversation

@smeckler
Copy link

@smeckler smeckler commented Nov 21, 2025

resolves #3332

Summary of changes

For SPARQL construct queries, send mime types for RDF instead of for SPARQL results in the header of the HTTP request.
Some SPARQL servers (in my case Anzo) respond with a 400 'Bad Request' response if the Accept header does not describe RDF for construct or describe queries.

sparqlconnector.py

  • get the type of SPARQL query from the passed query string
  • if it's a construct or describe query, use an HTTP Accept header that represents an RDF serialization

plugin.py

  • register the TurtleParser for the mime type "application/x-turtle" (for compatibility with legacy systems)

Checklist

  • Checked that there aren't other open pull requests for
    the same change.

update:

  • Checked that all tests and type checking passes.
    7600 passed, 592 skipped, 331 xfailed, 36 xpassed, 36012 warnings in 139.91s (0:02:19)

Copy link
Contributor

@WhiteGobo WhiteGobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest also adding a test like test/test_store/test_store_sparqlstore_query.test_query_construct_format, where you check, that turtle is in request.headers['Accept'].

rdf_mimetype_map = [mime for mlist in FORMAT_MIMETYPE_MAP.values() for mime in mlist]

# use the matched returnType if it matches one of the rdf mime types
if self.returnFormat in FORMAT_MIMETYPE_MAP:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i remember we have different parsers available for Construct-queries and Select-queries. So i would rather see use of a variable self.returnFormatConstruct than reuse self.returnFormat. Of course, you would have to add it to __init__ too.

@WhiteGobo
Copy link
Contributor

WhiteGobo commented Nov 27, 2025

Because of the failing testrun, you can take a look into developers guide
you can run black and mypy for the exact errors and the autoformatting

poetry run mypy
poetry run black .

Apart from that, this looks fine, to me at least. Sorry for my misunderstanding in your issue description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SPARQLConnector] CONSTRUCT queries should use RDF media types in Accept header

2 participants