Skip to content

Commit 8151231

Browse files
committed
Fix ModuleNotFoundError for older pinned functions versions
1 parent 0ed9017 commit 8151231

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

azure_functions_worker/functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pathlib
66
import typing
77

8-
from azure.functions import DataType, Function
8+
from azure_functions_worker.utils.library_importer import Function
99

1010
from . import bindings as bindings_utils
1111
from . import protos
@@ -216,8 +216,7 @@ def validate_function_params(params: dict, bound_params: dict,
216216
param_bind_type, param_py_type)
217217

218218
if not checks_out:
219-
if binding.data_type is not DataType(
220-
protos.BindingInfo.undefined):
219+
if binding.data_type is not protos.BindingInfo.undefined:
221220
raise FunctionLoadError(
222221
func_name,
223222
f'{param.name!r} binding type "{binding.type}" '

azure_functions_worker/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from os import PathLike, fspath
1313
from typing import List, Optional, Dict
1414

15-
from azure.functions import Function, FunctionApp
15+
from .utils.library_importer import Function, FunctionApp
1616

1717
from . import protos, functions
1818
from .constants import MODULE_NOT_FOUND_TS_URL, SCRIPT_FILE_NAME, \
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import logging
4+
5+
"""
6+
File to import library dependencies.
7+
This file should be used to import any dependency from the library since
8+
directly importing azure.functions may cause ModuleNotFound error is the user
9+
has pinned their azure.functions to an older release version.
10+
11+
"""
12+
13+
14+
def get_azure_function():
15+
try:
16+
from azure.functions import Function as func
17+
return func
18+
except ImportError:
19+
logging.error("azure.functions is pinned to an older version. "
20+
"Please pin azure.functions to version 1.10.1 or higher")
21+
22+
23+
def get_azure_function_app():
24+
try:
25+
from azure.functions import FunctionApp as funcApp
26+
return funcApp
27+
except ImportError:
28+
logging.error("azure.functions is pinned to an older version. "
29+
"Please pin azure.functions to version 1.10.1 or higher")
30+
31+
32+
Function = get_azure_function()
33+
FunctionApp = get_azure_function_app()

0 commit comments

Comments
 (0)