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

VersionedGraphCollection "Redo" Doesn't Bring Changes Back to Same Graph Name #98

Open
rileywong311 opened this issue Jul 11, 2023 · 1 comment

Comments

@rileywong311
Copy link
Contributor

It appears that redo() for the VersionedGraphCollection, although indeed adding the changeset back to the collection, it doesn't do it under the same graph name. So if I serialize the entire graph collection after undoing and redoing, it appears in the graph/file, but if I serialize only the specific graph I specified originally, it no longer appears in the file even though it is part of the graph collection.

from brickschema.persistent import VersionedGraphCollection, Changeset
from brickschema.namespaces import A, BRICK
from rdflib import Namespace

vg = VersionedGraphCollection("sqlite://")

BLDG = Namespace("test:") 

with vg.new_changeset("my-building") as cs:
    cs.add((BLDG.zone1, A, BRICK.HVAC_Zone))

with vg.new_changeset("my-building") as cs:
    cs.add((BLDG.zone2, A, BRICK.HVAC_Zone))

vg.undo()
vg.redo()

vg.serialize("UndoRedo1.ttl") # serialize the entire graph collection
vg.graph_at(graph="my-building").serialize("UndoRedo2.ttl") # serialize only the graph "my-building"

A potential fix that seems to work might be this (persistent.py on line 171):

# persistent.py
# redo():
triple = pickle.loads(row["triple"])
graph = self.get_context(redo_record["graph"])
if row["is_insertion"]:
  graph.remove((triple[0], triple[1], triple[2]))
else:
  graph.add((triple[0], triple[1], triple[2]))
@gtfierro
Copy link
Member

Yes, I think this the right solution. Can you do a PR? Thanks for finding this!

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

2 participants