RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.14k stars 555 forks source link

SPARQLUpdateStore does not work with GraphDB endpoints #1251

Open robertbbb opened 3 years ago

robertbbb commented 3 years ago

I'm regularly using GraphDB with RDF libraries from a variety of languages, but could never make it with rdflib and hoped this will be solved in the major update that is 5.0.0. From what I was able to gather this is an issue of its SPARQLUpdateStore (which also happens to be weakly documented). The following is a piece of Python that attempts to write a graph into a GraphDB store.

from rdflib import Graph, URIRef
from rdflib.plugins.stores import sparqlstore
g=Graph(identifier=URIRef("http://example.org/mygraph"))
mystring="@prefix : <http://example.org/>. :John :livesIn :Vienna."
g.parse(data=mystring,format="turtle")
readURL="http://localhost:7200/repositories/myrepo"
writeURL="http://localhost:7200/repositories/myrepo/statements"
mystore=sparqlstore.SPARQLUpdateStore()
mystore.open((readURL,writeURL))
mystore.add_graph(g)

Not sure if I'm doing something wrong or if there's a problem with rdflib, but what I get is:

requests.exceptions.HTTPError: 415 Client Error: for url: http://localhost:7200/repositories/myrepo/statements

nicholascar commented 3 years ago

I can confirm that the code above with the following lines to add triples instead of add_graph works fine:

mystore.add((
    URIRef("http://example.org/John"),
    URIRef("http://example.org/livesIn"),
    URIRef("http://example.org/Vienna"),
))

I'll look into add_graph next.

nicholascar commented 3 years ago

Another follow-up: I don't get a 415 error with your code above, instead I get no failure but also not graph addition. If I mangle the .../statements URI then I get a 415.

Also, when I look in the GraphDB query log after running the original code, i.e. add_graph, I see:

[INFO ] 2021-02-08 21:10:42,973 [repositories/myrepo | c.o.t.m.MonitorRepositoryConnection] Incoming update:
CREATE GRAPH <http://example.org/mygraph>

So it looks to me like rdflib is passing the correct create graph message to GraphDB but GraphDB doesn't seem to be creating the graph correctly and there's no indication that the triples of the graph are being sent over.

Wehn I run CREATE GRAPH <http://example.org/mygraph> directly in GraphDB's owl SPARQL UI, I get the message The number of statements did not change. Update took 0.1s, minutes ago. and no indication that a graph has actually been created (i.e. it's not listed), so it appears:

  1. GraphDB doesn't create empty graphs with CREATE GRAPH <...>
  2. rdflib with add_graph is sending a CREATE GRAPH <...> command but no data
robertbbb commented 3 years ago

With mystore.add(...) I get the exact same 415 error. In GraphDB's log it shows the following (for both add and add_graph):

[INFO ] 2021-02-08 13:36:27,926 [repositories/myrepo | c.o.f.s.GraphDBProtocolExceptionResolver] Client sent bad request ( 415) org.eclipse.rdf4j.http.server.ClientHTTPException: Unsupported MIME type: null

What versions did you use to run add() successfully? My setup is:

GraphDB 9.4.1 Python 3.9.1-64bit rdflib 5.0.0 (as installed by SPARQLWrapper, not directly)

nicholascar commented 3 years ago

GraphDB 8.10
Python 3.7
RDFLib 5.0.0

Definitely something odd there as I'm really not getting 415 errors.

I might have to look into the SPARQLUpdateStore code to see what headers are emitted.

nicholascar commented 3 years ago

I think I'm seeing the same behavior with Jena/Fuseki too. add works fine but add_graph gives no error but doesn't seem to do anything

jgonggrijp commented 2 years ago

I suspect I'm seeing a flavor of this problem with insert and delete updates in Fuseki. I'm working with rdflib 5.0.0, too. No errors are thrown. When I do a delete { ?s ?p ?o } where { ?s ?p ?o } update on a non-empty graph, rdflib's local view of the graph is emptied, but when checking back on the Fuseki side, it turns out that the graph still contains all the triples from before. Similar effective-yet-not-effective effects are seen with insert.

I'm seeing this when calling rdflib.Graph.update on a named graph that has a SPARQLUpdateStore referincing a Fuseki server as its underlying store.