Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Missing pairedItem fixes #8394

Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions packages/nodes-base/nodes/Airtable/v1/AirtableV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,12 @@ export class AirtableV1 implements INodeType {
const downloadFieldNames = (
this.getNodeParameter('downloadFieldNames', 0) as string
).split(',');
const pairedItem = generatePairedItemData(items.length);
const data = await downloadRecordAttachments.call(
this,
responseData.records as IRecord[],
downloadFieldNames,
pairedItem,
);
return [data];
}
Expand Down
5 changes: 5 additions & 0 deletions packages/nodes-base/nodes/Airtable/v1/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
IPollFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
IPairedItemData,
} from 'n8n-workflow';

interface IAttachment {
Expand Down Expand Up @@ -100,10 +101,14 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions,
records: IRecord[],
fieldNames: string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = [];
for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = record as unknown as IDataObject;
for (const fieldName of fieldNames) {
if (record.fields[fieldName] !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ export async function execute(
returnData = responseData.records as INodeExecutionData[];

if (options.downloadFields) {
const pairedItem = generatePairedItemData(items.length);
return await downloadRecordAttachments.call(
this,
responseData.records as IRecord[],
options.downloadFields as string[],
pairedItem,
);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/nodes-base/nodes/Airtable/v2/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
IPollFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
IPairedItemData,
} from 'n8n-workflow';
import { ApplicationError } from 'n8n-workflow';
import type { IAttachment, IRecord } from '../helpers/interfaces';
Expand Down Expand Up @@ -87,6 +88,7 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions,
records: IRecord[],
fieldNames: string | string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> {
if (typeof fieldNames === 'string') {
fieldNames = fieldNames.split(',').map((item) => item.trim());
Expand All @@ -99,6 +101,9 @@ export async function downloadRecordAttachments(
const elements: INodeExecutionData[] = [];
for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = flattenOutput(record as unknown as IDataObject);
for (const fieldName of fieldNames) {
if (record.fields[fieldName] !== undefined) {
Expand Down
4 changes: 3 additions & 1 deletion packages/nodes-base/nodes/Merge/v1/MergeV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
import { deepCopy } from 'n8n-workflow';

import { oldVersionNotice } from '@utils/descriptions';
import { generatePairedItemData } from '../../../utils/utilities';

const versionDescription: INodeTypeDescription = {
displayName: 'Merge',
Expand Down Expand Up @@ -477,7 +478,8 @@ export class MergeV1 implements INodeType {
returnData.push.apply(returnData, this.getInputData(1));
}
} else if (mode === 'wait') {
returnData.push({ json: {} });
const pairedItem = generatePairedItemData(this.getInputData(0).length);
returnData.push({ json: {}, pairedItem });
}

return [returnData];
Expand Down
4 changes: 3 additions & 1 deletion packages/nodes-base/nodes/Merge/v2/MergeV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from './GenericFunctions';

import { optionsDescription } from './OptionsDescription';
import { generatePairedItemData } from '../../../utils/utilities';

const versionDescription: INodeTypeDescription = {
displayName: 'Merge',
Expand Down Expand Up @@ -599,7 +600,8 @@ export class MergeV2 implements INodeType {
returnData.push.apply(returnData, this.getInputData(1));
}
if (output === 'empty') {
returnData.push({ json: {} });
const itemData = generatePairedItemData(this.getInputData(0).length);
returnData.push({ json: {}, pairedItem: itemData });
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/nodes-base/nodes/NocoDB/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
IHookFunctions,
ILoadOptionsFunctions,
INodeExecutionData,
IPairedItemData,
IPollFunctions,
} from 'n8n-workflow';
import { jsonParse, NodeOperationError } from 'n8n-workflow';
Expand Down Expand Up @@ -106,11 +107,15 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions,
records: IDataObject[],
fieldNames: string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = [];

for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = record as unknown as IDataObject;
for (const fieldName of fieldNames) {
let attachments = record[fieldName] as IAttachment[];
Expand Down
2 changes: 2 additions & 0 deletions packages/nodes-base/nodes/NocoDB/NocoDB.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ export class NocoDB implements INodeType {
this,
responseData as IDataObject[],
downloadFieldNames,
[{ item: i }],
);
data.push(...response);
}
Expand Down Expand Up @@ -584,6 +585,7 @@ export class NocoDB implements INodeType {
this,
[responseData as IDataObject],
downloadFieldNames,
[{ item: i }],
);
const newItem = {
binary: data[0].binary,
Expand Down
6 changes: 5 additions & 1 deletion packages/nodes-base/nodes/Notion/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ILoadOptionsFunctions,
INodeExecutionData,
INodeProperties,
IPairedItemData,
IPollFunctions,
JsonObject,
} from 'n8n-workflow';
Expand Down Expand Up @@ -860,12 +861,15 @@ export type FileRecord = {
};
};
// prettier-ignore
export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: FileRecord[]): Promise<INodeExecutionData[]> {
export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: FileRecord[], pairedItem?: IPairedItemData[]): Promise<INodeExecutionData[]> {

const elements: INodeExecutionData[] = [];
for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} };
element.json = record as unknown as IDataObject;
if (pairedItem) {
element.pairedItems = pairedItem;
}
for (const key of Object.keys(record.properties)) {
if (record.properties[key].type === 'files') {
if (record.properties[key].files.length) {
Expand Down
4 changes: 3 additions & 1 deletion packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ export class NotionV2 implements INodeType {
responseData = responseData.results;
}
if (download) {
responseData = await downloadFiles.call(this, responseData as FileRecord[]);
responseData = await downloadFiles.call(this, responseData as FileRecord[], [
{ item: i },
]);
}
if (simple) {
responseData = simplifyObjects(responseData, download);
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Redis/Redis.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class Redis implements INodeType {

let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
item = { json: {} };
item = { json: {}, pairedItem: { item: itemIndex } };

if (operation === 'delete') {
const keyDelete = this.getNodeParameter('key', itemIndex) as string;
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Set/v1/SetV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class SetV1 implements INodeType {
const nodeVersion = this.getNode().typeVersion;

if (items.length === 0) {
items.push({ json: {} });
items.push({ json: {}, pairedItem: { item: 0 } });
}

const returnData: INodeExecutionData[] = [];
Expand Down
Loading