azure-cli: Az 2.48.1 ImportError: cannot import name 'Request' from partially initialized module 'requests.models'

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name az servicebus namespace create

Errors:

The command failed with an unexpected error. Here is the traceback:
cannot import name 'Request' from partially initialized module 'requests.models' (most likely due to a circular import) (C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\requests\models.pyc)
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 707, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 1156, in _is_poller
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 686, in poller_classes
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrestazure/__init__.py", line 28, in <module>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrestazure/azure_configuration.py", line 34, in <module>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/__init__.py", line 28, in <module>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/configuration.py", line 37, in <module>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/pipeline/__init__.py", line 52, in <module>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/__init__.py", line 135, in <module>
ImportError: cannot import name 'Request' from partially initialized module 'requests.models' (most likely due to a circular import) (C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\requests\models.pyc)

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here…
  • az servicebus namespace create --name ANY-VALID-NAME --sku Premium --resource-group MY-RG --location brazilsouth

Expected Behavior

Service successfully created. Just like with Az Cli 2.47.

Environment Summary

Windows-10-10.0.22621-SP0
Python 3.10.10
Installer: MSI

azure-cli 2.48.1

Extensions:
resource-graph 2.1.0

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Additional Context

I found that by removing the location parameter the command works again.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

It will be May 23

Thanks for the workaround @kairu-ms. Is there an expected time for the next release?

that is a very long time to get a fix. considering many if not all commands are broken by this, can you at least remove the broken release?

Sorry for the trouble. The fix will be included in the May 23th release. There is another workaround, which is to disable the command index using the “AZURE_CORE_USE_COMMAND_INDEX=False” environment variable. It can import requests module in main thread but it will slow down command loading time.

I’m having the same issue with an analytics workspace

azure-cli 2.48.1 azure-devops 0.26.0 Python (Linux) 3.10.10 (main, Apr 25 2023, 04:23:10) [GCC 11.3.0] Agent Version / Current image version: ‘20230426.1’

az monitor log-analytics workspace create --resource-group $ResourceGroup --workspace-name $WorkspaceName --ingestion-access 'Enabled' --location $Location --query-access 'Enabled' --quota '-1' --retention-time $WorkspaceRetention --sku $WorkspaceSku --tags ${BaseTags} -o $OutputFormat

2023-04-27T07:07:42.5962212Z Create the analytics workspace ‘ws-product-development’… 2023-04-27T07:07:44.2681051Z ERROR: The command failed with an unexpected error. Here is the traceback: 2023-04-27T07:07:44.2686325Z ERROR: cannot import name ‘Request’ from partially initialized module ‘requests.models’ (most likely due to a circular import) (/opt/az/lib/python3.10/site-packages/requests/models.py) 2023-04-27T07:07:44.2686892Z Traceback (most recent call last): 2023-04-27T07:07:44.2687446Z File “/opt/az/lib/python3.10/site-packages/knack/cli.py”, line 233, in invoke 2023-04-27T07:07:44.2687886Z cmd_result = self.invocation.execute(args) 2023-04-27T07:07:44.2688459Z File “/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/init.py”, line 663, in execute 2023-04-27T07:07:44.2688862Z raise ex 2023-04-27T07:07:44.2689417Z File “/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/init.py”, line 726, in _run_jobs_serially 2023-04-27T07:07:44.2689889Z results.append(self._run_job(expanded_arg, cmd_copy)) 2023-04-27T07:07:44.2690486Z File “/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/init.py”, line 707, in _run_job 2023-04-27T07:07:44.2690906Z if _is_poller(result): 2023-04-27T07:07:44.2691479Z File “/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/init.py”, line 1156, in _is_poller 2023-04-27T07:07:44.2691917Z return isinstance(obj, poller_classes()) 2023-04-27T07:07:44.2692474Z File “/opt/az/lib/python3.10/site-packages/azure/cli/core/util.py”, line 686, in poller_classes 2023-04-27T07:07:44.2692947Z from msrestazure.azure_operation import AzureOperationPoller 2023-04-27T07:07:44.2693513Z File “/opt/az/lib/python3.10/site-packages/msrestazure/init.py”, line 28, in <module> 2023-04-27T07:07:44.2694154Z from .azure_configuration import AzureConfiguration 2023-04-27T07:07:44.2694757Z File “/opt/az/lib/python3.10/site-packages/msrestazure/azure_configuration.py”, line 34, in <module> 2023-04-27T07:07:44.2695186Z from msrest import Configuration 2023-04-27T07:07:44.2695722Z File “/opt/az/lib/python3.10/site-packages/msrest/init.py”, line 28, in <module> 2023-04-27T07:07:44.2696164Z from .configuration import Configuration 2023-04-27T07:07:44.2696709Z File “/opt/az/lib/python3.10/site-packages/msrest/configuration.py”, line 37, in <module> 2023-04-27T07:07:44.2697122Z from .pipeline import Pipeline 2023-04-27T07:07:44.2697674Z File “/opt/az/lib/python3.10/site-packages/msrest/pipeline/init.py”, line 52, in <module> 2023-04-27T07:07:44.2698119Z from requests.structures import CaseInsensitiveDict 2023-04-27T07:07:44.2698668Z File “/opt/az/lib/python3.10/site-packages/requests/init.py”, line 135, in <module> 2023-04-27T07:07:44.2699106Z from .models import Request, Response, PreparedRequest 2023-04-27T07:07:44.2699864Z ImportError: cannot import name ‘Request’ from partially initialized module ‘requests.models’ (most likely due to a circular import) (/opt/az/lib/python3.10/site-packages/requests/models.py) 2023-04-27T07:07:44.2700845Z To check existing issues, please visit: https://github.com/Azure/azure-cli/issues 2023-04-27T07:07:44.2701285Z To open a new issue, please run az feedback

It will be May 23

Thanks for the workaround @kairu-ms. Is there an expected time for the next release?

It is solved for me as well! We use the Azure CLI for a lot of our pipelines, it is crazy to think that this can be broken in the hosted agent for weeks, this has been broken for over a month. There has to be better unit test and system tests to prevent this from happening.

Did the release go out?

Yes it did. It was released yesterday as 2.49.0 and can confirm it fixed the problem for me.

When is this going to be fixed?

It’s already fixed.

Are you using a hosted agent? I still see 20230507.1 as the image version.

image

Same for me. When is this going to be fixed? It’s breaking our release pipeline. When will the fix be available on Azure DevOps hosted agents?

@fvalencia12 this other workaround worked for me

Great… broken deployments. Service Bus is being moved to the top of my “move away from this technology” list! Any news on a fix?

The current workaround is adding --no-wait which will bypass the polling functions. And call xxxx wait command

We will update the packaged python version in the next release.