-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Great library, this is working pretty well for us!
One issue I'm facing is that you can add multiple duplicate edges, resulting in some instability in the API.
node = GraphNode.objects.get(id=1)
new_parent = GraphNode.objects.get(id=2)
node.add_parent(new_parent)
# can call this multiple times
node.add_parent(new_parent)
node.add_parent(new_parent)
# need to refresh the related manager
node.refresh_from_db(fields=['parents'])
print(node.parents)This results in 3 edges being created, all with the same parent and child pointers. This may be desired - it's still a valid graph. The issue comes when you try to delete the parent:
node = GraphNode.objects.get(id=1)
parent_to_remove = GraphNode.objects.get(id=2)
node.remove_parent(parent_to_remove)An exception is raised:
Exception Type: MultipleObjectsReturned
Exception Value: get() returned more than one GraphEdge -- it returned 3!
Should remove_parent() be changed from parent.children.through.objects.get(parent=parent, child=self).delete() to a .filter()?
Metadata
Metadata
Assignees
Labels
No labels