Skip to content

Commit

Permalink
fix: ensure default edge is not removed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zacharyhamm committed Dec 17, 2024
1 parent 68eca14 commit 4f947d3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/dal/src/workspace_snapshot/graph/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1781,14 +1781,15 @@ 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<NodeIndex> = graph
.edges_directed(source_idx, Outgoing)
.filter(|edge_ref| {
matches!(
edge_ref.weight().kind(),
EdgeWeightKind::Use { is_default: true }
)
) && edge_ref.target() != destination_idx
})
.map(|edge_ref| edge_ref.target())
.collect();
Expand Down

0 comments on commit 4f947d3

Please sign in to comment.