Skip to content

Commit 74e0509

Browse files
committed
fix(secrets): sequence workspace upsert/delete to avoid read-modify-write race
1 parent 614d156 commit 74e0509

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

apps/sim/app/workspace/[workspaceId]/settings/components/credentials/credentials-manager.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,17 @@ export function CredentialsManager() {
999999
if (personalChanged) {
10001000
mutations.push(savePersonalMutation.mutateAsync({ variables: validVariables }))
10011001
}
1002-
if (workspaceId && Object.keys(toUpsert).length) {
1003-
mutations.push(upsertWorkspaceMutation.mutateAsync({ workspaceId, variables: toUpsert }))
1004-
}
1005-
if (workspaceId && toDelete.length) {
1006-
mutations.push(removeWorkspaceMutation.mutateAsync({ workspaceId, keys: toDelete }))
1002+
if (workspaceId && (Object.keys(toUpsert).length || toDelete.length)) {
1003+
mutations.push(
1004+
(async () => {
1005+
if (Object.keys(toUpsert).length) {
1006+
await upsertWorkspaceMutation.mutateAsync({ workspaceId, variables: toUpsert })
1007+
}
1008+
if (toDelete.length) {
1009+
await removeWorkspaceMutation.mutateAsync({ workspaceId, keys: toDelete })
1010+
}
1011+
})()
1012+
)
10071013
}
10081014

10091015
await Promise.all(mutations)
@@ -1020,7 +1026,7 @@ export function CredentialsManager() {
10201026
queryClient.invalidateQueries({ queryKey: workspaceCredentialKeys.lists() })
10211027
}
10221028
}
1023-
// eslint-disable-next-line react-hooks/exhaustive-deps
1029+
// eslint-disable-next-line react-hooks/exhaustive-deps -- mutation objects and queryClient are stable (TanStack Query v5)
10241030
}, [isListSaving, envVars, workspaceVars, newWorkspaceRows, workspaceId])
10251031

10261032
const handleDiscardAndNavigate = useCallback(() => {

0 commit comments

Comments
 (0)