Python Code note ignores null / None

Describe the problem/error/question

I’m using Google Workspace API to update user’s details using Patch semantics.
To wipe something I have to specify field and set it to null, my payload is in Python so I’m setting it to None
This works fine when tested locally but node doesn’t return this specific data at all.

Please share your workflow

Examples with hardcoded state to simplify.
This will return a string “null”, obviously this get’s rejected by API because it’s a date field.

payload = {
  "organizations":
    [
      {
        "title": title,
        "department": department,
      }
    ],
  "relations": 
  [
    {
      "value": managerMail,
      "type": "manager"
    }
  ],
  "customSchemas":
  [
{
    "Patronum": {
      "startDate": hireDate,
      "endDate": "null",
    },
    "Employee_Information": {
      "Team": team,
      "Sub-team": subTeam,
      "Location": location,
      "Division": division,
      "Employment_Status": status,
    }
}
  ],
}

return payload

Screenshot 2024-10-23 at 11.32.38

If I instead use None node correctly recognises it as valid semantic and changes colour same as it would for False

payload = {
  "organizations":
    [
      {
        "title": title,
        "department": department,
      }
    ],
  "relations": 
  [
    {
      "value": managerMail,
      "type": "manager"
    }
  ],
  "customSchemas":
  [
{
    "Patronum": {
      "startDate": hireDate,
      "endDate": None,
    },
    "Employee_Information": {
      "Team": team,
      "Sub-team": subTeam,
      "Location": location,
      "Division": division,
      "Employment_Status": status,
    }
}
  ],
}

Screenshot 2024-10-23 at 11.36.52

As you can see field get’s completely removed from the JSON payload variable.

If we compare JSON output of this node with the JSON output of previous node we can see that n8n can and does handles null values outside of this example.
Screenshot 2024-10-23 at 11.38.46

Any ideas? am I missing something or is this a bug?

Information on your n8n setup

  • n8n version: 1.63.4
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own, main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: n8n cloud

Hey @Mateusz_Bijakowski , it does look like a bug to me. As a workaround, you can return stringify payload and than parse it in the following Code node.

Just to demo it,

1 Like

Hey,
Yes this works.
Interestingly I can’t get it to process all of the records. It fails in various ways if I try to get more than one done.

For bugs do we have a way to report them from here or shall I just email support?

Hey @Mateusz_Bijakowski , I’m raising the bug issue internally. Nothing else needed from your side for now. Thanks for reporting.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.