Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deleting node breaks JSON roundtrip #1516

@d-miketa

Description

@d-miketa

Information

  • rustworkx version: 0.17.1
  • Python version: 3.11

What is the current behavior?

JSON serialisation doesn't respect deleted nodes.

import rustworkx as rx

graph = rx.PyGraph()
graph.add_node("A")  # index 0
graph.add_node("B")  # index 1
graph.add_node("C")  # index 2
graph.remove_node(1)  # Remove middle node

print(f"Before JSON: {graph.node_indices()}")
json_str = rx.node_link_json(graph)
restored = rx.parse_node_link_json(json_str)
print(f"After JSON:  {restored.node_indices()}")

Buggy Behavior (BEFORE fix)

Before JSON: NodeIndices[0, 2]
After JSON:  NodeIndices[0, 1] 

Index 2 is renumbered as 1. I'd expect the graph to roundtrip as I refer to those indices in other objects.

Analogous to #1503

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions