azure-iot-cli-extension
azure-iot-cli-extension copied to clipboard
IoT Hub Device Twin Replace does not allow `null` values
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
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 }'
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?
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.