How to unset a field with Bulk Patch request?

I have…

  • Read the following guideline: Troubleshooting and Support | Squidex. I understand that my support request might get deleted if I do not follow the guideline.
  • Used code blocks with ``` to format my code examples like JSON or logs properly.

I’m submitting a…

  • Regression (a behavior that stopped working in a new release)
  • Bug report
  • Performance issue
  • Documentation issue or request

Current behavior

If I send the following JSON object in a bulk (bulkUpdateContents) against the API and use the PATCH method, fields that are set to NULL are not changed. The old value is retained.

In an article from 2021, this topic was discussed once before and a deployment was announced. LINK

Expected behavior

The value of a field can be unset with NULL, similar to the UI function unset value.

Minimal reproduction of the problem

Send an object via bulkUpdateContents and the PATCH method against the API. The de field contains a value before the request.

{
    name: {
      en: 'english translation text',
      de: null,
      es: null,
      fr: null,
      nl: null,
      pl: null,
      pt: null
    }
}

Environment

App Name:

  • Self hosted with docker
  • Self hosted with IIS
  • Self hosted with other version
  • Cloud version

npm Package Version: 1.2.1
Version: 7.13.0

Browser:

  • Chrome (desktop)
  • Chrome (Android)
  • Chrome (iOS)
  • Firefox
  • Safari (desktop)
  • Safari (iOS)
  • IE
  • Edge

Others:

What happens if you just keep it undefined?

I can try it. But here I immediately ask myself whether I have understood Patch correctly. Patch updates the content partially. What is not explicitly defined should not be deleted or changed. Right?

Or what do you mean by undefined?

Request object

The language key pt is not defined. The result is the same as before. The value for the pt key is not reset.

[{
   id: "Content Id",
   data: { name: { en: "Weight", de: "", es: "", fr: "", nl: "", pl: "" } },
},
{...}
]

Thank you for your quick response.

I had a look to the code and I am a little bit confused why “null” does not work. I have to investigate that.

But this is not the same as “unsetting” a value. “Unset” in the UI removes they key entirely. Which could make a difference depending on your fallback logic.

For updates there is the “$unset” syntax, like

{
  "field": {
    "iv": { "$unset": true }
  }
}

But it does not work for patch yet. I will have to look into both issues next week.

1 Like