From ea9d2b31e1e6f51872eb7d10283b645de3b17bec Mon Sep 17 00:00:00 2001 From: Nastya <55718143+anrusina@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:34:10 -0700 Subject: [PATCH] fix(378): ensure that undefined executions ids won't get into graph (#388) * fix(378): ensure that undefined executions ids won't get into graph Signed-off-by: Nastya Rusina --- src/components/Workflow/workflowQueries.ts | 24 ++++++++++++------- .../WorkflowGraph/WorkflowGraph.tsx | 6 ++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/Workflow/workflowQueries.ts b/src/components/Workflow/workflowQueries.ts index be5a3ea67..c0ebbf35e 100644 --- a/src/components/Workflow/workflowQueries.ts +++ b/src/components/Workflow/workflowQueries.ts @@ -1,3 +1,4 @@ +import { log } from 'common/log'; import { QueryInput, QueryType } from 'components/data/types'; import { extractTaskTemplates } from 'components/hooks/utils'; import { getNodeExecutionData } from 'models/Execution/api'; @@ -16,6 +17,7 @@ export function makeWorkflowQuery(queryClient: QueryClient, id: WorkflowId): Que extractTaskTemplates(workflow).forEach((task) => queryClient.setQueryData([QueryType.TaskTemplate, task.id], task), ); + return workflow; }, // `Workflow` objects (individual versions) are immutable and safe to @@ -25,20 +27,26 @@ export function makeWorkflowQuery(queryClient: QueryClient, id: WorkflowId): Que } export function makeNodeExecutionDynamicWorkflowQuery( - queryClient: QueryClient, parentsToFetch, ): QueryInput<{ [key: string]: any }> { return { queryKey: [QueryType.DynamicWorkflowFromNodeExecution, parentsToFetch], queryFn: async () => { return await Promise.all( - Object.keys(parentsToFetch).map((id) => { - const executionId = parentsToFetch[id]; - const data = getNodeExecutionData(executionId.id).then((value) => { - return { key: id, value: value }; - }); - return data; - }), + Object.keys(parentsToFetch) + .filter((id) => parentsToFetch[id]) + .map((id) => { + const executionId = parentsToFetch[id]; + if (!executionId) { + // TODO FC#377: This check and filter few lines abode need to be deleted + // when Branch node support would be added + log.error(`Graph missing info for ${id}`); + } + const data = getNodeExecutionData(executionId.id).then((value) => { + return { key: id, value: value }; + }); + return data; + }), ).then((values) => { const output: { [key: string]: any } = {}; for (let i = 0; i < values.length; i++) { diff --git a/src/components/WorkflowGraph/WorkflowGraph.tsx b/src/components/WorkflowGraph/WorkflowGraph.tsx index 34671c39e..5ddcc7a57 100644 --- a/src/components/WorkflowGraph/WorkflowGraph.tsx +++ b/src/components/WorkflowGraph/WorkflowGraph.tsx @@ -7,7 +7,7 @@ import { NonIdealState } from 'components/common/NonIdealState'; import { DataError } from 'components/Errors/DataError'; import { NodeExecutionsContext } from 'components/Executions/contexts'; import { WaitForQuery } from 'components/common/WaitForQuery'; -import { useQuery, useQueryClient } from 'react-query'; +import { useQuery } from 'react-query'; import { makeNodeExecutionDynamicWorkflowQuery } from 'components/Workflow/workflowQueries'; import { createDebugLogger } from 'common/log'; import { CompiledNode } from 'models/Node/types'; @@ -90,9 +90,7 @@ export const WorkflowGraph: React.FC = (props) => { }; const dynamicParents = checkForDynamicExeuctions(nodeExecutionsById, staticExecutionIdsMap); - const dynamicWorkflowQuery = useQuery( - makeNodeExecutionDynamicWorkflowQuery(useQueryClient(), dynamicParents), - ); + const dynamicWorkflowQuery = useQuery(makeNodeExecutionDynamicWorkflowQuery(dynamicParents)); const renderReactFlowGraph = (dynamicWorkflows) => { debug('DynamicWorkflows:', dynamicWorkflows); let mergedDag = dag;