Skip to content

fix(dependency_graph): remove_dependency leaves orphaned child nodes in graph #1041

@LalatenduMohanty

Description

@LalatenduMohanty

Parent: #878

Problem

DependencyGraph.remove_dependency() (added in #1035) removes a node and its incoming edges from parent nodes, but does not clean up child nodes that become orphaned. It also does not remove stale entries from the parents list on child nodes.

For example, if tomli==1.5 fails to bootstrap in --multiple-versions mode and is removed from the graph:

  • Its children (e.g., flit-core==3.11.0) remain in self.nodes even if no other node references them
  • flit-core==3.11.0.parents still contains a stale edge pointing to the deleted tomli==1.5 node

Orphaned nodes don't affect build order (traversal starts from ROOT), but they appear in the serialized graph JSON as unreachable noise.

Expected behavior

When a node is removed, its children should be checked for remaining parents. Children with no remaining parents should be removed recursively.

Suggested fix

  1. Collect child nodes before deletion
  2. Clean up parents list on children (remove stale edges to deleted node)
  3. Recursively remove children that have no remaining parents

Metadata

Metadata

Assignees

Labels

easyeasy task

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions