Skip to content

Commit

Permalink
fix(Postgres Node): Falsy query parameters ignored (#10960)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Sep 26, 2024
1 parent c7888ef commit 4a63cff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4a63cff

Please sign in to comment.