Prechádzať zdrojové kódy

Fix LMDB error when passing store to a new graph; all graph tests pass.

Stefano Cossu 5 rokov pred
rodič
commit
a69a1fbb70

+ 4 - 3
lakesuperior/model/graph/graph.pyx

@@ -368,7 +368,8 @@ cdef class SimpleGraph:
 
         Override in subclasses to accommodate for different init properties.
         """
-        return self.__class__(store=getattr(self, 'store'))
+        with self.store.txn_ctx():
+            return self.__class__(store=self.store)
 
 
     cpdef union_(self, SimpleGraph other):
@@ -388,7 +389,6 @@ cdef class SimpleGraph:
             BufferTriple *trp
 
         new_gr = self.empty_copy()
-        new_gr.store = self.store
 
         for gr in (self, other):
             cc.hashset_iter_init(&it, gr._triples)
@@ -1141,7 +1141,8 @@ cdef class Imr(SimpleGraph):
         """
         Create an empty instance carrying over some key properties.
         """
-        return self.__class__(uri=self.uri, store=getattr(self, 'store'))
+        with self.store.txn_ctx():
+            return self.__class__(uri=self.uri, store=self.store)
 
 
     def value(self, p, strict=False):

+ 3 - 1
tests/0_data_structures/test_graph.py

@@ -431,6 +431,8 @@ class TestImrOps:
         assert trp[3] not in gr3
         assert trp[4] not in gr3
 
+        assert gr3.uri == 'http://example.edu/imr01'
+
         gr3 = gr2 - gr1
 
         assert len(gr3) == 2
@@ -441,7 +443,7 @@ class TestImrOps:
         assert trp[4] in gr3
         assert trp[5] in gr3
 
-        assert gr3.uri == 'http://example.edu/imr01'
+        assert gr3.uri == 'http://example.edu/imr02'
 
 
     def test_ip_subtraction(self, trp):