fix(core): Fix expressions in webhook nodes(Form, Webhook) to access previous node's data (#10247)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Michael Kret 2024-08-01 11:21:58 +03:00 committed by GitHub
parent 1608d2527b
commit 88a170176a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 6 deletions

View file

@ -256,6 +256,10 @@ export async function executeWebhook(
// Prepare everything that is needed to run the workflow // Prepare everything that is needed to run the workflow
const additionalData = await WorkflowExecuteAdditionalData.getBase(); const additionalData = await WorkflowExecuteAdditionalData.getBase();
if (executionId) {
additionalData.executionId = executionId;
}
// Get the responseMode // Get the responseMode
const responseMode = workflow.expression.getSimpleParameterValue( const responseMode = workflow.expression.getSimpleParameterValue(
workflowStartNode, workflowStartNode,
@ -359,6 +363,7 @@ export async function executeWebhook(
additionalData, additionalData,
NodeExecuteFunctions, NodeExecuteFunctions,
executionMode, executionMode,
runExecutionData ?? null,
); );
Container.get(WorkflowStatisticsService).emit('nodeFetchedData', { Container.get(WorkflowStatisticsService).emit('nodeFetchedData', {
workflowId: workflow.id, workflowId: workflow.id,

View file

@ -4212,8 +4212,9 @@ export function getExecuteWebhookFunctions(
mode: WorkflowExecuteMode, mode: WorkflowExecuteMode,
webhookData: IWebhookData, webhookData: IWebhookData,
closeFunctions: CloseFunction[], closeFunctions: CloseFunction[],
runExecutionData: IRunExecutionData | null,
): IWebhookFunctions { ): IWebhookFunctions {
return ((workflow: Workflow, node: INode) => { return ((workflow: Workflow, node: INode, runExecutionData: IRunExecutionData | null) => {
return { return {
...getCommonWorkflowFunctions(workflow, node, additionalData), ...getCommonWorkflowFunctions(workflow, node, additionalData),
getBodyData(): IDataObject { getBodyData(): IDataObject {
@ -4274,10 +4275,21 @@ export function getExecuteWebhookFunctions(
fallbackValue?: any, fallbackValue?: any,
options?: IGetNodeParameterOptions, options?: IGetNodeParameterOptions,
): NodeParameterValueType | object => { ): NodeParameterValueType | object => {
const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = [];
let connectionInputData: INodeExecutionData[] = [];
let executionData: IExecuteData | undefined;
if (runExecutionData?.executionData !== undefined) {
executionData = runExecutionData.executionData.nodeExecutionStack[0];
if (executionData !== undefined) {
connectionInputData = executionData.data.main[0]!;
}
}
const additionalKeys = getAdditionalKeys(additionalData, mode, runExecutionData);
return getNodeParameter( return getNodeParameter(
workflow, workflow,
@ -4288,8 +4300,8 @@ export function getExecuteWebhookFunctions(
parameterName, parameterName,
itemIndex, itemIndex,
mode, mode,
getAdditionalKeys(additionalData, mode, null), additionalKeys,
undefined, executionData,
fallbackValue, fallbackValue,
options, options,
); );
@ -4336,5 +4348,5 @@ export function getExecuteWebhookFunctions(
}, },
nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id), nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id),
}; };
})(workflow, node); })(workflow, node, runExecutionData);
} }

View file

@ -466,6 +466,7 @@ export interface IGetExecuteWebhookFunctions {
mode: WorkflowExecuteMode, mode: WorkflowExecuteMode,
webhookData: IWebhookData, webhookData: IWebhookData,
closeFunctions: CloseFunction[], closeFunctions: CloseFunction[],
runExecutionData: IRunExecutionData | null,
): IWebhookFunctions; ): IWebhookFunctions;
} }

View file

@ -1237,6 +1237,7 @@ export class Workflow {
additionalData: IWorkflowExecuteAdditionalData, additionalData: IWorkflowExecuteAdditionalData,
nodeExecuteFunctions: INodeExecuteFunctions, nodeExecuteFunctions: INodeExecuteFunctions,
mode: WorkflowExecuteMode, mode: WorkflowExecuteMode,
runExecutionData: IRunExecutionData | null,
): Promise<IWebhookResponseData> { ): Promise<IWebhookResponseData> {
const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) { if (nodeType === undefined) {
@ -1258,6 +1259,7 @@ export class Workflow {
mode, mode,
webhookData, webhookData,
closeFunctions, closeFunctions,
runExecutionData,
); );
return nodeType instanceof Node return nodeType instanceof Node
? await nodeType.webhook(context) ? await nodeType.webhook(context)