Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions apps/sim/app/api/v1/logs/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
workflowUpdatedAt: workflow.updatedAt,
})
.from(workflowExecutionLogs)
.innerJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.leftJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.innerJoin(
permissions,
and(
eq(permissions.entityType, 'workspace'),
eq(permissions.entityId, workflow.workspaceId),
eq(permissions.entityId, workflowExecutionLogs.workspaceId),
eq(permissions.userId, userId)
)
)
Expand All @@ -64,17 +64,29 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
return NextResponse.json({ error: 'Log not found' }, { status: 404 })
}

const workflowSummary = {
id: log.workflowId,
name: log.workflowName,
description: log.workflowDescription,
color: log.workflowColor,
folderId: log.workflowFolderId,
userId: log.workflowUserId,
workspaceId: log.workflowWorkspaceId,
createdAt: log.workflowCreatedAt,
updatedAt: log.workflowUpdatedAt,
}
const workflowSummary = log.workflowName
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truthiness check for deleted workflow detection is inconsistent

Low Severity

The deleted-workflow check in v1/logs/[id]/route.ts uses JavaScript truthiness (log.workflowName) while v1/logs/route.ts uses nullish coalescing (log.workflowName ?? 'Deleted Workflow'). An empty-string workflow name would cause the [id] endpoint to show 'Deleted Workflow' for an existing workflow, while the list endpoint would correctly pass the empty string through. The internal API uses log.workflowId for this check, which is more reliable since it comes from workflowExecutionLogs (set to null on delete) and isn't subject to empty-string falsiness.

Additional Locations (1)

Fix in Cursor Fix in Web

? {
id: log.workflowId,
name: log.workflowName,
description: log.workflowDescription,
color: log.workflowColor,
folderId: log.workflowFolderId,
userId: log.workflowUserId,
workspaceId: log.workflowWorkspaceId,
createdAt: log.workflowCreatedAt,
updatedAt: log.workflowUpdatedAt,
}
: {
id: log.workflowId,
name: 'Deleted Workflow',
description: null,
color: null,
folderId: null,
userId: null,
workspaceId: null,
createdAt: null,
updatedAt: null,
}

const response = {
id: log.id,
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/v1/logs/executions/[executionId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export async function GET(
workflow: workflow,
})
.from(workflowExecutionLogs)
.innerJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.leftJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.innerJoin(
permissions,
and(
eq(permissions.entityType, 'workspace'),
eq(permissions.entityId, workflow.workspaceId),
eq(permissions.entityId, workflowExecutionLogs.workspaceId),
eq(permissions.userId, userId)
)
)
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/app/api/v1/logs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function GET(request: NextRequest) {
workflowDescription: workflow.description,
})
.from(workflowExecutionLogs)
.innerJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.leftJoin(workflow, eq(workflowExecutionLogs.workflowId, workflow.id))
.innerJoin(
permissions,
and(
Expand Down Expand Up @@ -168,8 +168,8 @@ export async function GET(request: NextRequest) {
if (params.details === 'full') {
result.workflow = {
id: log.workflowId,
name: log.workflowName,
description: log.workflowDescription,
name: log.workflowName ?? 'Deleted Workflow',
description: log.workflowDescription ?? null,
}

if (log.cost) {
Expand Down