Describe the problem/error/question
Hi all, I encountered strange behavior when I was implementing a Webhook Workflow. I want to implement a REST API endpoint PATCH /submissions/:id where I can update the status and external_id of a submission. I want to be able to update one attribute at a time or all at once, for example, update only status, update only external_id, or update both.
The issue I encountered is with the Code node, where I want to prepare the columns for the Update operation of the Postgres node, but somehow I seem to see one output on the UI but it is passed differently to the Postgres node.
This is the database structure:
create type test.submission_status as enum ('draft', 'published', 'invalid');
create table test.submissions
(
id integer generated by default as identity primary key,
status test.submission_status default 'draft'::test.submission_status not null,
external_id text,
created_at timestamp default CURRENT_TIMESTAMP not null,
updated_at timestamp default CURRENT_TIMESTAMP not null
)
Here is the curl of the request:
curl --request PATCH \
--url http://localhost:5678/webhook-test/140315f6-6ee3-4398-9066-54d6be601fa0/submissions/1 \
--header 'Content-Type: application/json' \
--data '{
"data": {
"attributes": {
"external_id": "R_123"
}
}
}'
The Working Code Node and Failing Code Node have the same output on the UI, but the Postgres node is failing for Failing Code Node because it is trying to update all the fields instead of just the changed one.
What is the error message (if any)?
When I update only the external_id, I receive:
null value in column "status" of relation "submissions" violates not-null constraint
Failing row contains (1, null, R_123, 2025-01-11 11:41:18.075582, 2025-01-11 11:41:18.075582).
Please share your workflow
Is there something wrong with the Code node? Am I missing something on Javascript coding? Is there something wrong with the Postgres node?
Share the output returned by the last node
Information on your n8n setup
- n8n version: 1.69.2
- Database (default: SQLite): postgres 17.2
- n8n EXECUTIONS_PROCESS setting (default: own, main): default
- Running n8n via (Docker, npm, n8n cloud, desktop app): docker
- Operating system: MacOS