Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
82 stars 64 forks source link

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

Closed F-Joachim closed 1 month ago

F-Joachim commented 7 months ago

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
digimaun commented 7 months ago

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 }'
F-Joachim commented 7 months ago

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?

vilit1 commented 1 month ago

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.