Skip to content

Commit 8685a85

Browse files
fix: set changed size when iterating the store's graphs (#3281)
* fix: set changed size when iterating the store's graphs * fix: materialise the iterator with list() so it doesn't change * chore: revert calling to store directly --------- Co-authored-by: Nicholas Car <[email protected]>
1 parent 9b14b8f commit 8685a85

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rdflib/plugins/stores/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def contexts(
556556
self, triple: Optional[_TripleType] = None
557557
) -> Generator[_ContextType, None, None]:
558558
if triple is None or triple == (None, None, None):
559-
return (context for context in self.__all_contexts)
559+
return (context for context in list(self.__all_contexts))
560560

561561
subj, pred, obj = triple
562562
try:

test/test_store/test_store_memorystore.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ def test_memory_store(get_graph):
2929
g.remove(triple1)
3030
assert len(g) == 1
3131
assert len(g.serialize()) > 0
32+
33+
34+
def test_sparql_bindings_creating_new_graph():
35+
# Test for https://github.com/RDFLib/rdflib/issues/3102
36+
dataset = rdflib.Dataset()
37+
# Create a graph
38+
dataset.graph(identifier="urn:example:graph")
39+
sparql_query = """
40+
SELECT *
41+
WHERE {
42+
GRAPH ?g_1 { }
43+
GRAPH ?g_2 { }
44+
}"""
45+
46+
# Ensure it doesn't raise RuntimeError: Set changed size during iteration
47+
results = dataset.query(sparql_query)
48+
assert len(results) == 1

0 commit comments

Comments
 (0)