From 4a63cff5ec722c810e3ff2bd7b0bb1e32f7f403b Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:09:13 +0300 Subject: [PATCH] fix(Postgres Node): Falsy query parameters ignored (#10960) --- .../nodes/Postgres/test/v2/operations.test.ts | 23 +++++++++++++++++++ .../database/executeQuery.operation.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts b/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts index aff8c740a5..0f97966769 100644 --- a/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts +++ b/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts @@ -46,6 +46,9 @@ const createMockExecuteFunction = (nodeParameters: IDataObject) => { node.parameters = { ...node.parameters, ...(nodeParameters as INodeParameters) }; return node; }, + evaluateExpression(str: string, _: number) { + return str.replace('{{', '').replace('}}', ''); + }, } as unknown as IExecuteFunctions; return fakeExecuteFunction; }; @@ -290,6 +293,26 @@ describe('Test PostgresV2, executeQuery operation', () => { nodeOptions, ); }); + + it('should call runQueries with falsy query replacements', async () => { + const nodeParameters: IDataObject = { + operation: 'executeQuery', + query: 'SELECT *\nFROM users\nWHERE username IN ($1, $2, $3)', + options: { + queryReplacement: '={{ 0 }}, {{ null }}, {{ 0 }}', + }, + }; + const nodeOptions = nodeParameters.options as IDataObject; + + expect(async () => { + await executeQuery.execute.call( + createMockExecuteFunction(nodeParameters), + runQueries, + items, + nodeOptions, + ); + }).not.toThrow(); + }); }); describe('Test PostgresV2, insert operation', () => { diff --git a/packages/nodes-base/nodes/Postgres/v2/actions/database/executeQuery.operation.ts b/packages/nodes-base/nodes/Postgres/v2/actions/database/executeQuery.operation.ts index 4e6100e575..d103abd399 100644 --- a/packages/nodes-base/nodes/Postgres/v2/actions/database/executeQuery.operation.ts +++ b/packages/nodes-base/nodes/Postgres/v2/actions/database/executeQuery.operation.ts @@ -80,7 +80,7 @@ export async function execute( const rawReplacements = (node.parameters.options as IDataObject)?.queryReplacement as string; const stringToArray = (str: NodeParameterValueType | undefined) => { - if (!str) return []; + if (str === undefined) return []; return String(str) .split(',') .filter((entry) => entry)