Skip to content

Commit

Permalink
fix(378): ensure that undefined executions ids won't get into graph (#…
Browse files Browse the repository at this point in the history
…388)

* fix(378): ensure that undefined executions ids won't get into graph

Signed-off-by: Nastya Rusina <nastya@union.ai>
  • Loading branch information
anrusina authored Apr 14, 2022
1 parent 05b88ed commit ea9d2b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 16 additions & 8 deletions src/components/Workflow/workflowQueries.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand All @@ -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++) {
Expand Down
6 changes: 2 additions & 4 deletions src/components/WorkflowGraph/WorkflowGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -90,9 +90,7 @@ export const WorkflowGraph: React.FC<WorkflowGraphProps> = (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;
Expand Down

0 comments on commit ea9d2b3

Please sign in to comment.