azure-iot-cli-extension icon indicating copy to clipboard operation
azure-iot-cli-extension copied to clipboard

IoT Hub Device Twin Replace does not allow `null` values

Open F-Joachim opened this issue 1 year ago • 2 comments

Describe the bug I am trying to remove a specific tag from the tags object by setting it to null. But the azure-cli throws an error, that the property cannot be null.

Error {'Message': 'ErrorCode:ArgumentInvalid;Value of Property or Tag cannot be null. Error in Property/Tag my-tag', 'ExceptionMessage': 'Tracking ID:<tracking-id>-G:0-TimeStamp:11/28/2023 11:47:44'}

To Reproduce Steps to reproduce the behavior:

az iot hub device-twin replace \
  --device-id my-edge-device \
  --hub-name my-iot-hub \
  --json '{ "tags": { "my-tag": null } }'

Expected behavior The tag is set to null and therefore the whole tag will be removed from the Device Twin...in the same way as it works in the Azure Portal.

Environment:

mcr.microsoft.com/azure-cli:2.54.0
azure-iot extension 0.23.0

F-Joachim avatar Nov 28 '23 12:11 F-Joachim

Hi @F-Joachim can you please try using the device-twin update command? Example:

az iot hub device-twin update \
  --device-id my-edge-device \
  --hub-name my-iot-hub \
  --tags '{ "my-tag": null }'

digimaun avatar Nov 28 '23 18:11 digimaun

Hi @digimaun,

thanks for your reply. Yes, the update command works as expected. Is the replace command not intended for the deletion of certain tags?

F-Joachim avatar Nov 29 '23 04:11 F-Joachim

Replace is intended to set the device-twin properties and tags, which cannot be set to null. Thus, replace cannot be used to delete specific tags. Please use update if you want to delete specific tags.

vilit1 avatar May 13 '24 18:05 vilit1