From cc80c9c356e62596335bc8f1a81acb1016eaed74 Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Thu, 4 Aug 2022 22:16:10 +0200 Subject: [PATCH] fix: passing ConjunctiveGraph as namespace_manager (#2073) pass the NamespaceManager of the ConjunctiveGraph as namespace_manager of the Graph created by the get_context() method instead of the ConjunctiveGraph object itself. --- CHANGELOG.md | 16 ++++++++++++++++ rdflib/graph.py | 3 +-- .../test_conjunctive_graph.py | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a011613a..d61633865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,22 @@ CHANGE BARRIER is intended to reduce the potential for merge conflicts and will be removed for release. --> + + + + + + + - Fixes passing `NamespaceManager` in `ConjunctiveGraph`'s method `get_context()`. + The `get_context()` method will now pass the `NamespaceManager` of `ConjunctiveGraph` to the `namespace_manager` attribute of the newly created context graph, instead of the `ConjunctiveGraph` object itself. This cleans up an old FIXME commment. + [PR #2073](https://github.com/RDFLib/rdflib/pull/2073). + + + + + + + diff --git a/rdflib/graph.py b/rdflib/graph.py index d2713aea9..7dc69dad0 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -1915,9 +1915,8 @@ def get_context( identifier must be a URIRef or BNode. """ - # TODO: FIXME - why is ConjunctiveGraph passed as namespace_manager? return Graph( - store=self.store, identifier=identifier, namespace_manager=self, base=base # type: ignore[arg-type] + store=self.store, identifier=identifier, namespace_manager=self.namespace_manager, base=base # type: ignore[arg-type] ) def remove_context(self, context): diff --git a/test/test_conjunctivegraph/test_conjunctive_graph.py b/test/test_conjunctivegraph/test_conjunctive_graph.py index d6802f3f0..f26cb77ef 100644 --- a/test/test_conjunctivegraph/test_conjunctive_graph.py +++ b/test/test_conjunctivegraph/test_conjunctive_graph.py @@ -6,6 +6,7 @@ import pytest from rdflib import ConjunctiveGraph, Graph +from rdflib.namespace import NamespaceManager from rdflib.parser import StringInputSource from rdflib.term import BNode, Identifier, URIRef @@ -47,6 +48,17 @@ def test_quad_contexts(): assert isinstance(q[3], Graph) +def test_context_namespaces(): + cg = ConjunctiveGraph() + a = URIRef("urn:a") + ns = URIRef("http://example.org/") + cg.bind("ex", ns) + g = cg.get_context(a) + + assert type(g.namespace_manager) is NamespaceManager + assert ("ex", ns) in g.namespace_manager.namespaces() + + def get_graph_ids_tests(): def check(kws): cg = ConjunctiveGraph()