azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

[BUG] AttributeError: module 'azure.functions._abc' has no attribute 'SqlRow'

Open bowdenk7 opened this issue 2 years ago • 6 comments

I think #1029 might need to be re-opened.

  • Timestamp: 2022-06-16 -> 2022-06-17
  • Function App name: anomalyScoring
  • Function name(s) (as appropriate): there is only one on that function app
  • Core Tools version: 4?

Repro steps

Provide the steps required to reproduce the problem:

Have a perfectly good, deployed function. It starts failing after no changes from us with the error:

Result: Failure Exception: AttributeError: module 'azure.functions._abc' has no attribute 'SqlRow'

Known workarounds

Provide a description of any known workarounds.

Redeploying resolved the issue.

Contents of the requirements.txt file:

Provide the requirements.txt file to help us find out module related issues.
@@ -0,0 +1,9 @@
# DO NOT include azure-functions-worker in this file
# The Python Worker is managed by Azure Functions platform
# Manually managing azure-functions-worker may cause unexpected issues

azure-functions
pandas
numpy
scikit-learn
matplotlib

Seems exactly like #1029. The first time my production service went down because of this I was annoyed. But mistakes happen. The fact that we are getting this exact same issue again is pretty unacceptable. I know the guidance is:

# DO NOT include azure-functions-worker in this file
# The Python Worker is managed by Azure Functions platform
# Manually managing azure-functions-worker may cause unexpected issues

but I would like to know how I can lock onto a functioning version of the worker so yall can't keep breaking my production workloads.

Stacktrace

Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: Failure Exception: AttributeError: module 'azure.functions._abc' has no attribute 'SqlRow' Stack:
 File'/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py', line 324, in _handle__function_load_request     ExtensionManager.function_load_extension(
 File'/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 16, in call     return func(*args, **kwargs)
 File'/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py', line 65, in function_load_extension     sdk = cls._try_get_sdk_with_extension_enabled()
 File'/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py', line 225, in _try_get_sdk_with_extension_enabled     sdk = get_sdk_from_sys_path()
 File'/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/common.py', line 121, in get_sdk_from_sys_path     module = importlib.import_module('azure.functions')
 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/.python_packages/lib/site-packages/azure/functions/__init__.py', line 20, in <module>     from ._sql import SqlRow, SqlRowList
 File'/home/site/wwwroot/.python_packages/lib/site-packages/azure/functions/_sql.py', line 10, in <module>     class SqlRow(_abc.SqlRow, collections.UserDict): 

bowdenk7 avatar Jun 17 '22 16:06 bowdenk7

Facing similar issue

Exception: AttributeError: module 'azure.functions' has no attribute 'SqlRowList'

Core Tools Version: 4.0.4629

kihtrakinam avatar Jul 11 '22 11:07 kihtrakinam

Facing a similar issue.

Functions working locally with the 'azure-functions' package version 1.11.3b1, as suggested in docs. When run locally the functions are executing correctly and both retrieving data from, and writing to the Azure SQL Server.

Building locally, with app setting PYTHON_ISOLATE_WORKER_DEPENDENCIES set to "1", on a python runtime of 3.9, and extensionBundle.Preview of 4.* - 5.0.0

All other dependencies are working fine, and the deployed bundle contains the correct version of 'azure-functions', with SQL bindings.

Deployment to both regions "Norway East" and "Europe West" are resulting in:

AttributeError: module 'azure.functions._abc' has no attribute 'SqlRow'

From a Timer trigger function that does not use SQL bindings.

AttributeError: module 'azure.functions' has no attribute 'SqlRowList'

On a HTTP trigger function with both Input and Output SQL bindings.

poulDanielsen avatar Aug 13 '22 12:08 poulDanielsen

Having a similar issue, but running locally.

It looks like Azure Function Core Tools is ignoring the installed version of Azure Functions from the requirements.txt file, and actually using its bundled code installed through npm. You can check that there isn't any _sql.py file in the following path (which is the one being run locally): C:\Users\%USERPROFILE%\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.9\WINDOWS\X64\azure\functions

As a quick and dirty workaround, you can manually replace the contents of the previously mentioned folder with the contents in the official Azure Functions Python Library repo . This should do the job, until an official release fixes this issue.

However, this workaround only works if you have problems on local development. I haven't got to the deployment part yet, but I've read here that if you redeploy to the Central US region, for some reason it works.

godofred avatar Aug 16 '22 23:08 godofred

Just tested the deployment, and the very same code is working on the cloud as well.

I tested it on a East US region Function App service. Just remember to set the Application Settings correctly on the Settings -> Configuration -> Application Settings, through Azure Portal. Specially the PYTHON_ISOLATE_WORKER_DEPENDENCIES (set to 1) and the SqlConnectionString (set to whatever DB you're trying to connect)

godofred avatar Aug 17 '22 19:08 godofred

Downgrading azure-functions to 1.11.0 is a workaround for now.

azure-functions==1.11.0

Add this to the requirements.txt and redeploy.

CoAct-Atif avatar Aug 19 '22 01:08 CoAct-Atif

This has now been resolved for my currently deployed functions on "Europe West", without me changing any code.

Seems like the workers running in that region have been updated.

poulDanielsen avatar Aug 22 '22 06:08 poulDanielsen

Same issue.

We have an Azure function that runs every hour in East US region. It was running successfully until midnight UTC 2022-11-08. Now it's failing.

Is anyone in a position to know what changed and if it's going to be fixed?

BSickmillerArchaea avatar Nov 08 '22 16:11 BSickmillerArchaea

Downgrading azure-functions to 1.11.0 is a workaround for now.

azure-functions==1.11.0

Add this to the requirements.txt and redeploy.

This workaround worked for our function. Thanks, @CoAct-Atif!

BSickmillerArchaea avatar Nov 08 '22 18:11 BSickmillerArchaea

@BSickmillerArchaea - Can you please share the function name? https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately for us to investigate?

/cc @gavin-aguiar

vrdmr avatar Nov 08 '22 18:11 vrdmr

@BSickmillerArchaea - Can you please share the function name? https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately for us to investigate?

/cc @gavin-aguiar

(Reason='Timer fired at 2022-11-08T00:01:39.5694520+00:00', Id=dcf90174-94e4-45b7-9e40-2a4599a7261e)

Is this enough information for you?

Thanks!

BSickmillerArchaea avatar Nov 08 '22 18:11 BSickmillerArchaea

Microsoft has changed their documentation accordingly now: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-sql?tabs=in-process%2Cextensionv4&pivots=programming-language-python

It works with azure-functions==1.11.3b1 and "PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1" in your application settings (local and deployed).

At least it does for me.

image

MagnusWagner-WIT avatar Nov 14 '22 10:11 MagnusWagner-WIT

I rolled back the azure-functions==1.11.0 workaround to azure-functions in requirements.txt and set PYTHON_ISOLATE_WORKER_DEPENDENCIES to 1 in the Azure AppSettings as suggested by @MagnusWagner-WIT and things are still working as expected.

This seems like the "correct" solution (correct me if I'm wrong), so we are going to stick with this solution unless things break or we hear otherwise.

BSickmillerArchaea avatar Nov 15 '22 21:11 BSickmillerArchaea

@BSickmillerArchaea is that a typo?

Azure SQL Binding support was not introduced until 1.11.1 https://github.com/Azure/azure-functions-python-library/releases/tag/1.11.1

lamym avatar Dec 05 '22 22:12 lamym

@lamym, no typo. We initially downgraded to azure-functions==1.11.0 as suggested by @CoAct-Atif as a workaround to our function suddenly beginning to fail out of the blue. See thread further up for details.

After implementing @MagnusWagner-WIT's suggestion to set PYTHON_ISOLATE_WORKER_DEPENDENCIES to 1 in the Azure AppSettings, we were able to roll back the previous workaround.

BSickmillerArchaea avatar Dec 08 '22 17:12 BSickmillerArchaea