mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(Google Sheets Node): Do not insert row_number as a new column, do not checkForSchemaChanges in update operation (#10201)
This commit is contained in:
parent
2eba57774b
commit
5136d10ca3
|
@ -5,11 +5,12 @@ import type {
|
||||||
ResourceMapperField,
|
ResourceMapperField,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeOperationError } from 'n8n-workflow';
|
import { NodeOperationError } from 'n8n-workflow';
|
||||||
import type {
|
import {
|
||||||
ISheetUpdateData,
|
ROW_NUMBER,
|
||||||
SheetProperties,
|
type ISheetUpdateData,
|
||||||
ValueInputOption,
|
type SheetProperties,
|
||||||
ValueRenderOption,
|
type ValueInputOption,
|
||||||
|
type ValueRenderOption,
|
||||||
} from '../../helpers/GoogleSheets.types';
|
} from '../../helpers/GoogleSheets.types';
|
||||||
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
||||||
import {
|
import {
|
||||||
|
@ -312,7 +313,7 @@ export async function execute(
|
||||||
};
|
};
|
||||||
|
|
||||||
const addNewColumn = (key: string) => {
|
const addNewColumn = (key: string) => {
|
||||||
if (!columnNames.includes(key)) {
|
if (!columnNames.includes(key) && key !== ROW_NUMBER) {
|
||||||
newColumns.add(key);
|
newColumns.add(key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
import type {
|
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||||
IExecuteFunctions,
|
|
||||||
IDataObject,
|
|
||||||
INodeExecutionData,
|
|
||||||
ResourceMapperField,
|
|
||||||
} from 'n8n-workflow';
|
|
||||||
import { NodeOperationError } from 'n8n-workflow';
|
import { NodeOperationError } from 'n8n-workflow';
|
||||||
import type {
|
import {
|
||||||
ISheetUpdateData,
|
ROW_NUMBER,
|
||||||
SheetProperties,
|
type ISheetUpdateData,
|
||||||
ValueInputOption,
|
type SheetProperties,
|
||||||
ValueRenderOption,
|
type ValueInputOption,
|
||||||
|
type ValueRenderOption,
|
||||||
} from '../../helpers/GoogleSheets.types';
|
} from '../../helpers/GoogleSheets.types';
|
||||||
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
||||||
import {
|
import { cellFormatDefault, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
|
||||||
cellFormatDefault,
|
|
||||||
checkForSchemaChanges,
|
|
||||||
untilSheetSelected,
|
|
||||||
} from '../../helpers/GoogleSheets.utils';
|
|
||||||
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
|
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
|
||||||
|
|
||||||
export const description: SheetProperties = [
|
export const description: SheetProperties = [
|
||||||
|
@ -262,11 +254,6 @@ export async function execute(
|
||||||
|
|
||||||
columnNames = sheetData[keyRowIndex];
|
columnNames = sheetData[keyRowIndex];
|
||||||
|
|
||||||
if (nodeVersion >= 4.4) {
|
|
||||||
const schema = this.getNodeParameter('columns.schema', 0) as ResourceMapperField[];
|
|
||||||
checkForSchemaChanges(this.getNode(), columnNames, schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
const newColumns = new Set<string>();
|
const newColumns = new Set<string>();
|
||||||
|
|
||||||
const columnsToMatchOn: string[] =
|
const columnsToMatchOn: string[] =
|
||||||
|
@ -305,7 +292,7 @@ export async function execute(
|
||||||
};
|
};
|
||||||
|
|
||||||
const addNewColumn = (key: string) => {
|
const addNewColumn = (key: string) => {
|
||||||
if (!columnNames.includes(key)) {
|
if (!columnNames.includes(key) && key !== ROW_NUMBER) {
|
||||||
newColumns.add(key);
|
newColumns.add(key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -343,11 +343,16 @@ export function checkForSchemaChanges(
|
||||||
) {
|
) {
|
||||||
const updatedColumnNames: Array<{ oldName: string; newName: string }> = [];
|
const updatedColumnNames: Array<{ oldName: string; newName: string }> = [];
|
||||||
|
|
||||||
|
//if sheet does not contain ROW_NUMBER ignore it as data come from read rows operation
|
||||||
|
const schemaColumns = columnNames.includes(ROW_NUMBER)
|
||||||
|
? schema.map((s) => s.id)
|
||||||
|
: schema.filter((s) => s.id !== ROW_NUMBER).map((s) => s.id);
|
||||||
|
|
||||||
for (const [columnIndex, columnName] of columnNames.entries()) {
|
for (const [columnIndex, columnName] of columnNames.entries()) {
|
||||||
const schemaEntry = schema[columnIndex];
|
const schemaEntry = schemaColumns[columnIndex];
|
||||||
if (schemaEntry === undefined) break;
|
if (schemaEntry === undefined) break;
|
||||||
if (columnName !== schema[columnIndex].id) {
|
if (columnName !== schemaEntry) {
|
||||||
updatedColumnNames.push({ oldName: schema[columnIndex].id, newName: columnName });
|
updatedColumnNames.push({ oldName: schemaEntry, newName: columnName });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue