Skip to content

[bug] az iot hub state export fails with KeyError: 'x509Thumbprint' #746

@Bogdan-Catalin

Description

@Bogdan-Catalin

Describe the bug
Backing up an IoTHub instance, after running the script for 2h 30mins we get a KeyError: 'x509Thumbprint' crash .

To Reproduce
In our case it was enough to run az iot hub state export --hub-name prod-hub --state-file state.json.

Expected behavior
The statefile should have been generated without errors.

Screenshots
Are full stack traces allowed here ?

Saving devices and modules:  73%|###################################################################################################################                                           | 19903/27177 [2:36:34<57:13,  2.12it/s]
The command failed with an unexpected error. Here is the traceback:
'x509Thumbprint'
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.74.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/redacteduser/.azure/cliextensions/azure-iot/azext_iot/iothub/commands_state.py", line 29, in state_export
    sp.save_state(state_file, replace, hub_aspects)
  File "/Users/redacteduser/.azure/cliextensions/azure-iot/azext_iot/iothub/providers/state.py", line 102, in save_state
    hub_state = self.process_hub_to_dict(self.target, hub_aspects)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacteduser/.azure/cliextensions/azure-iot/azext_iot/iothub/providers/state.py", line 235, in process_hub_to_dict
    devices = self.download_devices(target=target)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/redacteduser/.azure/cliextensions/azure-iot/azext_iot/iothub/providers/state.py", line 591, in download_devices
    module_twin.pop(key)
KeyError: 'x509Thumbprint'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Environment (please complete the following information):

  • OS: MacOS 15.5
  • Shell: zsh
  • Az CLI version: 2.74
  • IoT extension version: 0.26.0
  • Python version (if pip installed): python 3.12, pip 25.1.1

Additional context
We managed to get this working by modifying here to module_twin.pop(key, None) and for good measure here to module.pop(key, None).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions