Skip to content

Commit b48613f

Browse files
jrangelramosclaude
andcommitted
fix: skip duplicate Analysis stage in approve & upgrade flow
When an ApprovalPolicy auto-approves the Analysis stage, clicking "Approve & upgrade" would fail with a duplicate key error because the stage was unconditionally added again. Now checks if the Analysis stage already exists before calling approveStage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bdf72d8 commit b48613f

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/components/update-plan/DecisionActions.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ const DecisionActions: React.FC<DecisionActionsProps> = ({ proposal, clusterVers
4444
[approvals, proposal.metadata?.name, proposal.metadata?.namespace],
4545
);
4646

47-
const { approveStage, denyStage, error, clearError, inProgress } =
48-
useApprovalActions(approval);
47+
const { approveStage, denyStage, error, clearError, inProgress } = useApprovalActions(approval);
4948

5049
const [confirmingApprove, setConfirmingApprove] = React.useState(false);
5150
const [confirmingDeny, setConfirmingDeny] = React.useState(false);
@@ -66,8 +65,11 @@ const DecisionActions: React.FC<DecisionActionsProps> = ({ proposal, clusterVers
6665
setConfirmingApprove(false);
6766
setUpgradeError(null);
6867

69-
const approved = await approveStage('Analysis');
70-
if (!approved) return;
68+
const alreadyApproved = approval?.spec?.stages?.some((s) => s.type === 'Analysis');
69+
if (!alreadyApproved) {
70+
const approved = await approveStage('Analysis');
71+
if (!approved) return;
72+
}
7173

7274
const rawTarget = proposal.metadata?.labels?.[LABELS.targetVersion] ?? '';
7375
const targetVersion = rawTarget ? unsanitizeVersion(rawTarget) : '';
@@ -109,7 +111,15 @@ const DecisionActions: React.FC<DecisionActionsProps> = ({ proposal, clusterVers
109111
setConfirmingApprove(false);
110112
}, CONFIRM_TIMEOUT_MS);
111113
}
112-
}, [confirmingApprove, approveStage, proposal, clusterVersion, history, t]);
114+
}, [
115+
confirmingApprove,
116+
approveStage,
117+
approval?.spec?.stages,
118+
proposal,
119+
clusterVersion,
120+
history,
121+
t,
122+
]);
113123

114124
const handleDenyClick = React.useCallback(async () => {
115125
if (confirmingDeny) {

0 commit comments

Comments
 (0)