Skip to content

SPARQLStore won't work with preparedQuery #2055

@aucampia

Description

@aucampia

When using a graph with SPARQLStore, Graph.query will call Store.query:

rdflib/rdflib/graph.py

Lines 1381 to 1391 in 0856ac8

if hasattr(self.store, "query") and use_store_provided:
try:
return self.store.query(
query_object,
initNs,
initBindings,
self.default_union and "__UNION__" or self.identifier,
**kwargs,
)
except NotImplementedError:
pass # store has no own implementation

And this will then proceed to assert that the query is a str:

def query(
self,
query,
initNs=None, # noqa: N803
initBindings=None,
queryGraph=None,
DEBUG=False,
):
self.debug = DEBUG
assert isinstance(query, str)

And even without this assert, things won't work unless it is a str.

This is not an ideal situation, a better situation would be one of:

  1. Either don't support query objects, and only strings
  2. Obtain a string for the query object in SPARQLStore
  3. Have a different methods for working with prepared query

Either way, the interface of Store ideally should have a good match with all the implementations of it that comes with RDFLib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstoreRelated to a store.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions