Skip to content
Merged
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
13 changes: 11 additions & 2 deletions packages/server/src/services/export-import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { Tool } from '../../database/entities/Tool'
import { Variable } from '../../database/entities/Variable'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils'
import { Platform } from '../../Interface'
import assistantsService from '../../services/assistants'
import chatflowsService from '../../services/chatflows'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { checkUsageLimit } from '../../utils/quotaUsage'
import { sanitizeNullBytes } from '../../utils/sanitize.util'
import assistantService from '../assistants'
import chatMessagesService from '../chat-messages'
import chatflowService from '../chatflows'
Expand All @@ -25,8 +27,6 @@ import executionService, { ExecutionFilters } from '../executions'
import marketplacesService from '../marketplaces'
import toolsService from '../tools'
import variableService from '../variables'
import { Platform } from '../../Interface'
import { sanitizeNullBytes } from '../../utils/sanitize.util'

type ExportInput = {
agentflow: boolean
Expand Down Expand Up @@ -596,6 +596,15 @@ function reduceSpaceForChatflowFlowData(chatflows: ChatFlow[]) {
function insertWorkspaceId(importedData: any, activeWorkspaceId?: string) {
if (!activeWorkspaceId) return importedData
importedData.forEach((item: any) => {
if (item.type === 'Tool') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The condition item.type === 'Tool' is a bit fragile. While it currently works because Tool entities don't have a type property, this could change in the future. If a Tool object ever gets a type: 'Tool' property, this code would add a flowData property to it. Since the Tool entity doesn't have a flowData column, this would cause a database error upon saving.

A more robust check would be to also verify that the item is a CustomTemplate. A simple way to do this is to check for a property that exists on CustomTemplate but not on Tool, like badge.

Suggested change
if (item.type === 'Tool') {
if (item.type === 'Tool' && 'badge' in item) {

// TODO: This is a temporary fix where export data for CustomTemplate type Tool need to be changed in the future.
// Also handles backward compatibility for previously exported data where CustomTemplate type Tool does not have flowData field.
item.flowData = JSON.stringify({
iconSrc: item.iconSrc,
schema: item.schema,
func: item.func
})
}
item.workspaceId = activeWorkspaceId
})
return importedData
Expand Down
Loading