From 7ae6d03949184e2e0ac8dad8e0ee58e2a9947a50 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Wed, 25 Sep 2024 10:40:04 +0300 Subject: [PATCH] fix --- .../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 aff8c740a5c11..0f979667697c2 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 4e6100e5755a2..d103abd399000 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)