Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset is not unpickled correctly #893

Closed
iddan opened this issue Jan 20, 2019 · 2 comments
Closed

Dataset is not unpickled correctly #893

iddan opened this issue Jan 20, 2019 · 2 comments

Comments

@iddan
Copy link

iddan commented Jan 20, 2019

Dataset is unpickeld as ConjuctiveGraph because it extends ConjuctiveGraph and inherits the __reduce__() method. It should be unpickled as Dataset instead.

@iddan iddan changed the title Dataset is not pickled correctly Dataset is not unpickled correctly Jan 20, 2019
@iddan
Copy link
Author

iddan commented Feb 7, 2019

I've managed to fix it:

from rdflib.graph import Dataset

class FixedDataset(Dataset):
    def __reduce__(self):
        return (type(self), (self.store, self.default_union))

    def __getstate__(self):
        return self.store, self.identifier, self.default_context, self.default_union

    def __setstate__(self, state):
        self.store, self.identifier, self.default_context, self.default_union = state

# TEST

import pickle
from rdflib.namespace import Namespace

example = Namespace("http://example.com#")

fixed = FixedDataset()
one = fixed.graph(example.one)

one.add((example.dan, example.knows, example.lisa))
one.add((example.lisa, example.knows, example.dan))

two = fixed.graph(example.two)

two.add((example.ben, example.knows, example.lisa))
two.add((example.lisa, example.knows, example.ben))

assert set(fixed.quads((None, None, None, None))) == set(fixed.quads((None, None, None, None)))

picklestring = pickle.dumps(fixed)
new_fixed = pickle.loads(picklestring)

for new_graph, graph in zip(new_fixed.graphs(), fixed.graphs()):
    assert new_graph.identifier == graph.identifier
    for new_triple, triple in zip(new_graph.triples((None, None, None)), graph.triples((None, None, None))):
        assert new_triple == triple

@ghost ghost mentioned this issue Dec 12, 2021
@ghost
Copy link

ghost commented Dec 19, 2021

Fixed in #1501

@ghost ghost closed this as completed Dec 19, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant