Skip to content

Commit bf083f1

Browse files
committed
pass workspace id in correctly
1 parent 125a02e commit bf083f1

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ export async function POST(
7676
return createErrorResponse('Invalid deployed state structure', 500)
7777
}
7878

79+
if (!workflowRecord?.workspaceId) {
80+
return createErrorResponse('Workflow has no workspace', 500)
81+
}
82+
7983
const { blocks: migratedBlocks } = await applyBlockMigrations(
8084
deployedState.blocks,
81-
workflowRecord?.workspaceId ?? undefined
85+
workflowRecord.workspaceId
8286
)
8387

8488
const saveResult = await saveWorkflowToNormalizedTables(id, {

apps/sim/app/api/workflows/[id]/deployments/[version]/route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export async function GET(
5353
const { id, version } = await params
5454

5555
try {
56-
const { error } = await validateWorkflowPermissions(id, requestId, 'read')
56+
const { error, workflow: workflowRecord } = await validateWorkflowPermissions(
57+
id,
58+
requestId,
59+
'read'
60+
)
5761
if (error) {
5862
return createErrorResponse(error.message, error.status)
5963
}
@@ -78,9 +82,13 @@ export async function GET(
7882
return createErrorResponse('Deployment version not found', 404)
7983
}
8084

85+
if (!workflowRecord?.workspaceId) {
86+
return createErrorResponse('Workflow has no workspace', 500)
87+
}
88+
8189
const state = row.state as { blocks?: Record<string, BlockState> }
8290
if (state.blocks) {
83-
const { blocks } = await applyBlockMigrations(state.blocks)
91+
const { blocks } = await applyBlockMigrations(state.blocks, workflowRecord.workspaceId)
8492
state.blocks = blocks
8593
}
8694

apps/sim/lib/workflows/persistence/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export async function loadDeployedWorkflowState(
117117
resolvedWorkspaceId = wfRow?.workspaceId ?? undefined
118118
}
119119

120+
if (!resolvedWorkspaceId) {
121+
throw new Error(`Workflow ${workflowId} has no workspace`)
122+
}
123+
120124
const { blocks: migratedBlocks } = await applyBlockMigrations(
121125
state.blocks || {},
122126
resolvedWorkspaceId
@@ -139,7 +143,7 @@ export async function loadDeployedWorkflowState(
139143

140144
interface MigrationContext {
141145
blocks: Record<string, BlockState>
142-
workspaceId?: string
146+
workspaceId: string
143147
migrated: boolean
144148
}
145149

@@ -148,7 +152,7 @@ type BlockMigration = (ctx: MigrationContext) => MigrationContext | Promise<Migr
148152
function createMigrationPipeline(migrations: BlockMigration[]) {
149153
return async (
150154
blocks: Record<string, BlockState>,
151-
workspaceId?: string
155+
workspaceId: string
152156
): Promise<{ blocks: Record<string, BlockState>; migrated: boolean }> => {
153157
let ctx: MigrationContext = { blocks, workspaceId, migrated: false }
154158
for (const migration of migrations) {
@@ -170,7 +174,6 @@ export const applyBlockMigrations = createMigrationPipeline([
170174
}),
171175

172176
async (ctx) => {
173-
if (!ctx.workspaceId) return ctx
174177
const { blocks, migrated } = await migrateCredentialIds(ctx.blocks, ctx.workspaceId)
175178
return { ...ctx, blocks, migrated: ctx.migrated || migrated }
176179
},
@@ -409,9 +412,13 @@ export async function loadWorkflowFromNormalizedTables(
409412
blocksMap[block.id] = assembled
410413
})
411414

415+
if (!workflowRow?.workspaceId) {
416+
throw new Error(`Workflow ${workflowId} has no workspace`)
417+
}
418+
412419
const { blocks: finalBlocks, migrated } = await applyBlockMigrations(
413420
blocksMap,
414-
workflowRow?.workspaceId ?? undefined
421+
workflowRow.workspaceId
415422
)
416423

417424
if (migrated) {

0 commit comments

Comments
 (0)