From 4f947d3ea05fbe97dbdafd454f48db19c95f42e8 Mon Sep 17 00:00:00 2001 From: Zachary Hamm Date: Tue, 17 Dec 2024 14:58:30 -0600 Subject: [PATCH] fix: ensure default edge is not removed If a new edge update comes in that sets a schema variant to the default, but that variant is already default, we end up with no default. I'm not sure why this update is being produced (since there should be no difference in this case for the edge in question), but this prevents the issue from arising. --- lib/dal/src/workspace_snapshot/graph/v4.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/dal/src/workspace_snapshot/graph/v4.rs b/lib/dal/src/workspace_snapshot/graph/v4.rs index 990828549d..c793b66aee 100644 --- a/lib/dal/src/workspace_snapshot/graph/v4.rs +++ b/lib/dal/src/workspace_snapshot/graph/v4.rs @@ -1631,7 +1631,7 @@ impl WorkspaceSnapshotGraphV4 { if let (Some(source_idx), Some(destination_idx)) = (source_idx, destination_idx) { if let EdgeWeightKind::Use { is_default: true } = edge_weight.kind() { - ensure_only_one_default_use_edge(self, source_idx)?; + ensure_only_one_default_use_edge(self, source_idx, destination_idx)?; } self.add_edge_inner( @@ -1781,6 +1781,7 @@ fn prop_node_indexes_for_node_index( fn ensure_only_one_default_use_edge( graph: &mut WorkspaceSnapshotGraphV4, source_idx: NodeIndex, + destination_idx: NodeIndex, ) -> WorkspaceSnapshotGraphResult<()> { let existing_default_targets: Vec = graph .edges_directed(source_idx, Outgoing) @@ -1788,7 +1789,7 @@ fn ensure_only_one_default_use_edge( matches!( edge_ref.weight().kind(), EdgeWeightKind::Use { is_default: true } - ) + ) && edge_ref.target() != destination_idx }) .map(|edge_ref| edge_ref.target()) .collect();