Skip to content

Commit

Permalink
Fixed undefined task input types access in NodeExecutionActions (flyt…
Browse files Browse the repository at this point in the history
…eorg#538)

* Fixed undefined task input types access in NodeExecutionActions
Issue occurred due to race condition while loading data, indentical fix applies as for flyteorg#506

Signed-off-by: Nick Müller <[email protected]>

* fix: cannot read properties of undefined (flyteorg#506)

fix: nullref

Signed-off-by: Carina Ursu <[email protected]>

Co-authored-by: Carina Ursu <[email protected]>
(cherry picked from commit d38b98b2d68700415224ad6c621d79e928fded01)

Signed-off-by: Nick Müller <[email protected]>

Co-authored-by: Carina Ursu <[email protected]>
  • Loading branch information
Nick Müller and ursucarina authored Jul 6, 2022
1 parent 59d5d2a commit 7e44dca
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Dialog, IconButton } from '@material-ui/core';
import * as React from 'react';
import { ResourceIdentifier, Identifier, Variable } from 'models/Common/types';
import { ResourceIdentifier, Identifier } from 'models/Common/types';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { getTask } from 'models/Task/api';
import { LaunchFormDialog } from 'components/Launch/LaunchForm/LaunchFormDialog';
Expand Down Expand Up @@ -67,37 +67,42 @@ export const ExecutionDetailsActions = (props: ExecutionDetailsActionsProps): JS
const styles = useStyles();

const [showLaunchForm, setShowLaunchForm] = React.useState<boolean>(false);
const [taskInputsTypes, setTaskInputsTypes] = React.useState<
Record<string, Variable> | undefined
>();

const [initialParameters, setInitialParameters] = React.useState<
TaskInitialLaunchParameters | undefined
>(undefined);

const executionData = useNodeExecutionData(nodeExecutionId);
const execution = useNodeExecution(nodeExecutionId);

const id = details.taskTemplate?.id as ResourceIdentifier | undefined;
const id = details.taskTemplate?.id;

React.useEffect(() => {
const fetchTask = async () => {
const task = await getTask(id as Identifier);
setTaskInputsTypes(task.closure.compiledTask.template?.interface?.inputs?.variables);
};
if (id) fetchTask();
}, [id]);
if (!id) {
return;
}

(async () => {
const task = await getTask(id!);

const literals = executionData.value.fullInputs?.literals;
const taskInputsTypes = task.closure.compiledTask.template?.interface?.inputs?.variables;

const tempInitialParameters: TaskInitialLaunchParameters = {
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes),
taskId: id as Identifier | undefined,
};

setInitialParameters(tempInitialParameters);
})();
}, [details]);

const [showDeck, setShowDeck] = React.useState(false);
const onCloseDeck = () => setShowDeck(false);

if (!id) {
if (!id || !initialParameters) {
return <></>;
}

const literals = executionData.value.fullInputs?.literals;

const initialParameters: TaskInitialLaunchParameters = {
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes),
taskId: id as Identifier | undefined,
};

const rerunOnClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation();
setShowLaunchForm(true);
Expand All @@ -121,7 +126,7 @@ export const ExecutionDetailsActions = (props: ExecutionDetailsActionsProps): JS
</Button>
</div>
<LaunchFormDialog
id={id}
id={id as ResourceIdentifier}
initialParameters={initialParameters}
showLaunchForm={showLaunchForm}
setShowLaunchForm={setShowLaunchForm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NodeExecution } from 'models/Execution/types';
import * as React from 'react';
import InputsAndOutputsIcon from '@material-ui/icons/Tv';
import { RerunIcon } from '@flyteconsole/ui-atoms';
import { Identifier, ResourceIdentifier, Variable } from 'models/Common/types';
import { Identifier, ResourceIdentifier } from 'models/Common/types';
import { LaunchFormDialog } from 'components/Launch/LaunchForm/LaunchFormDialog';
import { getTask } from 'models/Task/api';
import { useNodeExecutionData } from 'components/hooks/useNodeExecution';
Expand All @@ -27,13 +27,12 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem
const [nodeExecutionDetails, setNodeExecutionDetails] = React.useState<
NodeExecutionDetails | undefined
>();
const [taskInputsTypes, setTaskInputsTypes] = React.useState<
Record<string, Variable> | undefined
>();
const [initialParameters, setInitialParameters] = React.useState<
TaskInitialLaunchParameters | undefined
>(undefined);

const executionData = useNodeExecutionData(execution.id);
const literals = executionData.value.fullInputs?.literals;
const id = nodeExecutionDetails?.taskTemplate?.id as ResourceIdentifier;
const id = nodeExecutionDetails?.taskTemplate?.id;

React.useEffect(() => {
detailsContext.getNodeExecutionDetails(execution).then((res) => {
Expand All @@ -42,11 +41,23 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem
});

React.useEffect(() => {
const fetchTask = async () => {
if (!id) {
return;
}

(async () => {
const task = await getTask(id as Identifier);
setTaskInputsTypes(task.closure.compiledTask.template?.interface?.inputs?.variables);
};
if (id) fetchTask();

const literals = executionData.value.fullInputs?.literals;
const taskInputsTypes = task.closure.compiledTask.template?.interface?.inputs?.variables;

const tempInitialParameters: TaskInitialLaunchParameters = {
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes),
taskId: id as Identifier | undefined,
};

setInitialParameters(tempInitialParameters);
})();
}, [id]);

// open the side panel for selected execution's detail
Expand All @@ -63,14 +74,10 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem
};

const renderRerunAction = () => {
if (!id) {
if (!id || !initialParameters) {
return <></>;
}

const initialParameters: TaskInitialLaunchParameters = {
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes),
taskId: id as Identifier | undefined,
};
return (
<>
<Tooltip title={t('rerunTooltip')}>
Expand All @@ -79,7 +86,7 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem
</IconButton>
</Tooltip>
<LaunchFormDialog
id={id}
id={id as ResourceIdentifier}
initialParameters={initialParameters}
showLaunchForm={showLaunchForm}
setShowLaunchForm={setShowLaunchForm}
Expand Down

0 comments on commit 7e44dca

Please sign in to comment.