fix(Postgres Node): Falsy query parameters ignored (#10960)

This commit is contained in:
Michael Kret 2024-09-26 18:09:13 +03:00 committed by GitHub
parent c7888ef229
commit 4a63cff5ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -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', () => {

View file

@ -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)