Closed vtechev closed 1 year ago
I am facing the same issue. I am able to import and run locally with no issue, however when deploying to my azure function app I get the same circular import error.
I have been able to resolve this issue. It's not the result of a bug in UAMQP, but in the deployment method. "local" deployments fail to correctly install some libraries including UAMQP for reasons that have something to do with binaries and wheels.
The solution is to do a "remote" deployment. How to do this depends on how you're deploying in the first place.
For those using Azure DevOps pipelines, like me, according to the documentation if your app has ENABLE_ORYX_BUILD and SCM_DO_BUILD_DURING_DEPLOYMENT set to 'true', then the deploy stage of the pipeline should do a remote build. For me it ignored those settings and did a local build anyway, which you can detect by looking for the WEBSITE_RUN_FROM_PACKAGE value being set to point to a zip file in blob storage. This may have happened to me because I used the Consumption Plan.
I was eventually able to write a pipeline that worked after consulting this thread, which discusses using a task to install the azure functions core tools on the pipeline VM. Unfortunately I can't share my final pipeline.
Thanks to Haitham Shahin over at Microsoft for helping me get on the right track.
@vtechev this was the only thing that helped me in the whole wide internet. Thanks!
This is how it looks like in Github Actions:
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy function
shell: bash
run: |-
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
cd <YOUR_FUNCTION_ROOT>
func azure functionapp publish <FUNCTION_APP_NAME> --build remote
I still have the same issue. Has anyone figured out how to get this working on ubuntu?
We now have released the latest azure-eventhub that is using the new python based amqp library. It would be great if you can give that a try. If there are issues with the client library please open an issue on the sdk repo
Result: Failure Exception: ImportError: cannot import name 'c_uamqp' from partially initialized module 'uamqp' (most likely due to a circular import) (/home/site/wwwroot/.python_packages/lib/site-packages/uamqp/__init__.py). Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 315, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 42, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/loader.py", line 85, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/home/site/wwwroot/function/__init__.py", line 7, in <module> from azure.eventhub.aio import EventHubConsumerClient File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/eventhub/__init__.py", line 5, in <module> from uamqp import constants File "/home/site/wwwroot/.python_packages/lib/site-packages/uamqp/__init__.py", line 12, in <module> from uamqp import c_uamqp # pylint: disable=import-self
init.py is as follows:
I find that this error occurs even in a minimal app with no business logic, which I have published here Linked repository includes an azure-pipelines.yaml, which differs from my own only in that the value of the ‘azureSubscription’ variable has been stripped.
This issue appears similar to #281, which is open after some information was requested of the submitter. With regard to that requested information, “could you help verify locally that even just with the simplest import you will get the failure as well?”, I am able to import these modules locally without raising an ImportError. The error only appears when the code is deployed to the cloud.
To Reproduce Steps to reproduce the behavior: 1) Create an Azure Function app Python 3.9 runtime stack and Linux operating system 2) Deploy code provided in the repository linked above
Expected behavior The message “Started function.” should appear in invocation traces.