Skip to content

Commit

Permalink
fix(Google Sheets Node): Do not insert row_number as a new column, do…
Browse files Browse the repository at this point in the history
… not checkForSchemaChanges in update operation (#10201)
  • Loading branch information
michael-radency authored and cstuncsik committed Jul 31, 2024
1 parent 2fef71e commit 848d1b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import type {
ResourceMapperField,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type {
ISheetUpdateData,
SheetProperties,
ValueInputOption,
ValueRenderOption,
import {
ROW_NUMBER,
type ISheetUpdateData,
type SheetProperties,
type ValueInputOption,
type ValueRenderOption,
} from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import {
Expand Down Expand Up @@ -312,7 +313,7 @@ export async function execute(
};

const addNewColumn = (key: string) => {
if (!columnNames.includes(key)) {
if (!columnNames.includes(key) && key !== ROW_NUMBER) {
newColumns.add(key);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type {
IExecuteFunctions,
IDataObject,
INodeExecutionData,
ResourceMapperField,
} from 'n8n-workflow';
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type {
ISheetUpdateData,
SheetProperties,
ValueInputOption,
ValueRenderOption,
import {
ROW_NUMBER,
type ISheetUpdateData,
type SheetProperties,
type ValueInputOption,
type ValueRenderOption,
} from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import {
cellFormatDefault,
checkForSchemaChanges,
untilSheetSelected,
} from '../../helpers/GoogleSheets.utils';
import { cellFormatDefault, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';

export const description: SheetProperties = [
Expand Down Expand Up @@ -262,11 +254,6 @@ export async function execute(

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 columnsToMatchOn: string[] =
Expand Down Expand Up @@ -305,7 +292,7 @@ export async function execute(
};

const addNewColumn = (key: string) => {
if (!columnNames.includes(key)) {
if (!columnNames.includes(key) && key !== ROW_NUMBER) {
newColumns.add(key);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,16 @@ export function checkForSchemaChanges(
) {
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()) {
const schemaEntry = schema[columnIndex];
const schemaEntry = schemaColumns[columnIndex];
if (schemaEntry === undefined) break;
if (columnName !== schema[columnIndex].id) {
updatedColumnNames.push({ oldName: schema[columnIndex].id, newName: columnName });
if (columnName !== schemaEntry) {
updatedColumnNames.push({ oldName: schemaEntry, newName: columnName });
}
}

Expand Down

0 comments on commit 848d1b7

Please sign in to comment.