Skip to content

Commit f9e6952

Browse files
committed
add registry none check
1 parent c9a63be commit f9e6952

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

azure_functions_worker/bindings/meta.py

+19-30
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,15 @@ def load_binding_registry() -> None:
4343

4444

4545
def get_binding(bind_name: str, pytype: typing.Optional[type] = None) -> object:
46-
try:
47-
# Check if binding is deferred binding
48-
binding = get_deferred_binding(bind_name=bind_name, pytype=pytype)
49-
# Binding is not deferred binding type
50-
if binding is None:
51-
binding = BINDING_REGISTRY.get(bind_name)
52-
# Binding is generic
53-
if binding is None:
54-
binding = generic.GenericBinding
55-
return binding
56-
except AttributeError:
57-
# If BINDING_REGISTRY is None, azure-functions hasn't been loaded
58-
# in correctly.
59-
raise AttributeError("BINDING_REGISTRY is None.")
46+
# Check if binding is deferred binding
47+
binding = get_deferred_binding(bind_name=bind_name, pytype=pytype)
48+
# Binding is not deferred binding type
49+
if binding is None:
50+
binding = BINDING_REGISTRY.get(bind_name)
51+
# Binding is generic
52+
if binding is None:
53+
binding = generic.GenericBinding
54+
return binding
6055

6156

6257
def is_trigger_binding(bind_name: str) -> bool:
@@ -219,22 +214,16 @@ def to_outgoing_param_binding(binding: str, obj: typing.Any, *,
219214

220215
def get_deferred_binding(bind_name: str,
221216
pytype: typing.Optional[type] = None) -> object:
222-
try:
223-
binding = None
224-
225-
# Checks if pytype is a supported sdk type
226-
if DEFERRED_BINDINGS_REGISTRY.check_supported_type(pytype):
227-
# Returns deferred binding converter
228-
binding = DEFERRED_BINDINGS_REGISTRY.get(bind_name)
229-
230-
# This will return None if not a supported type
231-
return binding
232-
except AttributeError:
233-
# This will catch if DEFERRED_BINDINGS_REGISTRY is None
234-
# It will be None if the library isn't imported
235-
# Ensure that the flag is set to False in this case
236-
global DEFERRED_BINDINGS_ENABLED
237-
DEFERRED_BINDINGS_ENABLED = False
217+
binding = None
218+
219+
# Checks if pytype is a supported sdk type
220+
if (DEFERRED_BINDINGS_REGISTRY is not None
221+
and DEFERRED_BINDINGS_REGISTRY.check_supported_type(pytype)):
222+
# Returns deferred binding converter
223+
binding = DEFERRED_BINDINGS_REGISTRY.get(bind_name)
224+
225+
# This will return None if not a supported type
226+
return binding
238227

239228

240229
def deferred_bindings_decode(binding: typing.Any,

azure_functions_worker/dispatcher.py

+8
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ async def _handle__worker_init_request(self, request):
300300
# loading bindings registry and saving results to a static
301301
# dictionary which will be later used in the invocation request
302302
bindings.load_binding_registry()
303+
if bindings.meta.BINDING_REGISTRY is None:
304+
# If BINDING_REGISTRY is None, azure-functions hasn't been loaded
305+
# in correctly.
306+
raise AttributeError("BINDING_REGISTRY is None.")
303307

304308
if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
305309
try:
@@ -637,6 +641,10 @@ async def _handle__function_environment_reload_request(self, request):
637641
# calling load_binding_registry again since the
638642
# reload_customer_libraries call clears the registry
639643
bindings.load_binding_registry()
644+
if bindings.meta.BINDING_REGISTRY is None:
645+
# If BINDING_REGISTRY is None, azure-functions hasn't been loaded
646+
# in correctly.
647+
raise AttributeError("BINDING_REGISTRY is None.")
640648

641649
if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
642650
try:

0 commit comments

Comments
 (0)