Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading