-
Notifications
You must be signed in to change notification settings - Fork 580
Open
Description
Hello,
I'm manipulating Dataset and I ended up in a weird situation where I have an Dataset instance, with triples in it, in a graph, but:
- I can't get get the graph. It's always empty
- If I serialise the dataset, it's empty.
- If I loop over the dataset quads, the data is there.
I couldn't reproduce the dataset with a simple code (it comes from a large code base), but I was able to dump it with pickle and reproduce the issue in the small script below.
import pickle
from rdflib import Dataset, URIRef
with open("/tmp/ds2.png", "rb") as fd:
ds2: Dataset = pickle.load(fd)
graph = URIRef("http://example.com/cde/#graph")
for i, (s, p, o, g) in enumerate(ds2):
assert g == graph # ok
print(i, s, p, o, g)
assert len(ds2) == 10, len(ds2) # ok
assert len(ds2.graph(graph)) == 10, len(ds2.graph(graph)) # fails
assert ds2.serialize(format="trig") != "\n" # failsoutput
0 http://example.com/cde/#guid http://example.com/cde/#ontology_version 0.0.0 http://example.com/cde/#graph
1 http://example.com/cde/#guid http://example.com/cde/#created_on 2025-11-26T12:16:21.555303+00:00 http://example.com/cde/#graph
2 http://example.com/cde/#guid http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.com/cde/#Claim http://example.com/cde/#graph
3 http://example.com/cde/#guid http://example.com/cde/#b hello http://example.com/cde/#graph
4 http://example.com/cde/#guid http://example.com/cde/#visibility_scope confidential http://example.com/cde/#graph
5 http://example.com/cde/#guid http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.com/cde/#Person http://example.com/cde/#graph
6 http://example.com/cde/#guid http://example.com/cde/#a 11 http://example.com/cde/#graph
7 http://example.com/cde/#guid http://example.com/cde/#last_update_on 2025-11-26T12:16:21.555309+00:00 http://example.com/cde/#graph
8 http://example.com/cde/#guid http://example.com/cde/#graph http://example.com/cde/#graph http://example.com/cde/#graph
9 http://example.com/cde/#guid http://example.com/cde/#created_by http://example.com/cde/#pytest http://example.com/cde/#graph
Traceback (most recent call last):
File "/home/pierre/workspace/.../back-api/./test02.py", line 39, in <module>
assert len(ds2.graph(graph)) == 10, len(ds2.graph(graph)) # fails
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0Would anyone have an idea ?
I'm using rdflib-7.4.0
Metadata
Metadata
Assignees
Labels
No labels
