Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SDK bindings changes #1423

Merged
merged 160 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 155 commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
a6df3c0
sdk working prototype
hallvictoria Nov 11, 2023
532549c
misc
hallvictoria Jan 10, 2024
ad66487
merge with dev
hallvictoria Jan 12, 2024
468fdbb
new registry pseudo
hallvictoria Jan 17, 2024
0e2aabd
prototype changes
hallvictoria Jan 24, 2024
ecaced1
weird dispatcher changes
hallvictoria Jan 24, 2024
3fda7b7
almost works
hallvictoria Jan 25, 2024
180e3e7
working prototype!!
hallvictoria Jan 26, 2024
f60ce9a
reset flag
hallvictoria Jan 29, 2024
fd888dc
support for mix & match in same func
hallvictoria Jan 30, 2024
abf92b9
added pytype to decode()
hallvictoria Jan 31, 2024
bc2e719
caching
hallvictoria Feb 12, 2024
54c2ca9
added tests
hallvictoria Feb 14, 2024
28620e4
revert later
hallvictoria Feb 22, 2024
3f50987
lint, clean up, templates
hallvictoria Feb 29, 2024
79fe387
Merge branch 'dev' into hallvictoria/sdk-bindings
hallvictoria Feb 29, 2024
e2aa249
reorder
hallvictoria Feb 29, 2024
ba506b9
merge
hallvictoria Feb 29, 2024
c8741a3
reorder again
hallvictoria Feb 29, 2024
29c8f5d
test pypi problems
hallvictoria Feb 29, 2024
7dabadb
correct dir
hallvictoria Feb 29, 2024
dda46a7
checking tests
hallvictoria Feb 29, 2024
24be05e
Merge branch 'dev' into hallvictoria/sdk-bindings
hallvictoria Mar 1, 2024
950310b
404s
hallvictoria Mar 1, 2024
e61f551
Merge branch 'hallvictoria/sdk-bindings' of https://github.com/Azure/…
hallvictoria Mar 1, 2024
0bdaa29
investigating 500s
hallvictoria Mar 1, 2024
b1f7510
no cache
hallvictoria Mar 1, 2024
5ac3503
debugging
hallvictoria Mar 1, 2024
7c102b8
more helpful debugging
hallvictoria Mar 1, 2024
e2bfe40
check raw bindings
hallvictoria Mar 1, 2024
3834da1
runtime error
hallvictoria Mar 1, 2024
0b90c69
runtime error logging attempt
hallvictoria Mar 1, 2024
3e0423b
local logger
hallvictoria Mar 1, 2024
971f26f
sys modules
hallvictoria Mar 4, 2024
9edeed6
typo
hallvictoria Mar 4, 2024
9ceddce
extensions version
hallvictoria Mar 4, 2024
c32082a
testing changes -- revert later
hallvictoria Mar 5, 2024
0677af2
added host logs
hallvictoria Mar 7, 2024
0b40754
spacing?
hallvictoria Mar 7, 2024
b9eb942
debugging changes
hallvictoria Mar 8, 2024
5f06186
Moved dateutil to install_requires (#1443)
gavin-aguiar Mar 8, 2024
967e067
Update Python Worker Version to 4.26.0
Mar 8, 2024
1c86b00
net8 target framework
hallvictoria Mar 11, 2024
33e3d03
stdout is not none
hallvictoria Mar 11, 2024
864f458
tests pass locally
hallvictoria Mar 11, 2024
d451301
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria Mar 11, 2024
ab94777
updating extension versions
hallvictoria Mar 11, 2024
54a8731
temp table test fix
hallvictoria Mar 11, 2024
2e4cfd9
table and eventhub test fix
hallvictoria Mar 12, 2024
cf155ec
all blob tests
hallvictoria Mar 12, 2024
1ed33b4
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
Mar 13, 2024
98d0eca
merge with dev
Mar 13, 2024
de91a09
Merge branch 'hallvictoria/sdk-bindings' of https://github.com/Azure/…
Mar 13, 2024
9581929
no importlib
Mar 13, 2024
9c0fb6e
specific tests only for deferred bindings
Mar 13, 2024
cc629f9
removed -e
Mar 13, 2024
882615b
syntax
Mar 13, 2024
25a4ada
ignore test, add back in cache
Mar 13, 2024
7606f4a
revert eh and table tests
Mar 13, 2024
aedd917
blob extension resources
Mar 13, 2024
6a67832
>=3.9 support + test fixes
hallvictoria Mar 14, 2024
d235c36
lint
hallvictoria Mar 14, 2024
8ffd054
removed testing changes
hallvictoria Mar 14, 2024
8109cfe
lint again
hallvictoria Mar 14, 2024
69b9d91
unit tests fix
hallvictoria Mar 15, 2024
90e05e7
append to list
hallvictoria Mar 15, 2024
5e644ce
fixes + tests
hallvictoria Mar 18, 2024
d532739
reset flag, extra test
hallvictoria Mar 18, 2024
c27ddbc
revert meta changes, tests passing locally
hallvictoria Mar 18, 2024
ae4f3d5
fixed tests
hallvictoria Mar 18, 2024
72cf2d7
fix unit test, import by default
Mar 18, 2024
937780e
revert default import, meta refactoring
Mar 18, 2024
1c3be18
fixed meta refactor
hallvictoria Mar 19, 2024
cf03600
added tests for helpers
hallvictoria Mar 19, 2024
8020ab9
type syntax
hallvictoria Mar 19, 2024
f13de2a
fixed tests
hallvictoria Mar 19, 2024
0f77d5d
actually fixed tests
hallvictoria Mar 19, 2024
c295a4f
update base ext supported python version
hallvictoria Mar 19, 2024
6dc75b9
fixing unit test timeouts?
hallvictoria Mar 19, 2024
22ae2a0
setup.py too
hallvictoria Mar 19, 2024
78eef60
installing from .[deferred-bindings]
Mar 20, 2024
df12dc0
update base ext supported python version again
Mar 20, 2024
ff75823
update var name in setup.py
Mar 20, 2024
8591fec
update var name in meta
Mar 20, 2024
c2fd15d
refactor tests into sep folder
Mar 20, 2024
ac78e7b
lint + install only .NET6
Mar 20, 2024
9d40991
remove script
Mar 20, 2024
8367f9e
edit workflow
Mar 20, 2024
f04c0e3
import by default, misc fixes
Mar 20, 2024
f9fa310
revert, only changed var name
Mar 20, 2024
14beca7
get_binding check
Mar 20, 2024
fc47c14
revert get_binding check, import by default
Mar 20, 2024
e3933f1
lint
Mar 20, 2024
91bbc18
rename, replace None checks, comments
hallvictoria Mar 21, 2024
2d70c05
fixed flag placement
hallvictoria Mar 21, 2024
e320a9e
attribute error + lint
hallvictoria Mar 22, 2024
1411dec
fixed unit tests
hallvictoria Mar 22, 2024
10a9039
yml bug/feature reports
hallvictoria Mar 22, 2024
e802d63
moving flag set out of get_binding
hallvictoria Mar 25, 2024
e80f37d
lint + 100
hallvictoria Mar 25, 2024
c9a63be
merge
Mar 27, 2024
f9e6952
add registry none check
hallvictoria Mar 29, 2024
29aefda
Merge branch 'dev' into hallvictoria/sdk-bindings
hallvictoria Mar 29, 2024
0937cd3
lint
hallvictoria Mar 29, 2024
249d0cd
Merge branch 'hallvictoria/sdk-bindings' of https://github.com/Azure/…
hallvictoria Mar 29, 2024
2dc368a
move check
hallvictoria Mar 29, 2024
b8c59f4
revert error raise
hallvictoria Mar 29, 2024
109c078
changed order
hallvictoria Mar 29, 2024
a591055
revert flag set
hallvictoria Mar 29, 2024
24fc8c1
loader registry none check
hallvictoria Mar 29, 2024
19bfd5f
adding back in checks
hallvictoria Mar 29, 2024
1b42eb8
reports & workflow feedback
hallvictoria Apr 2, 2024
4c69c18
permissions + consumption
hallvictoria Apr 2, 2024
afb444a
feedback
hallvictoria Apr 2, 2024
bbf865a
setup.py
hallvictoria Apr 2, 2024
21a7e0b
Merge branch 'dev' into hallvictoria/sdk-bindings
hallvictoria Apr 2, 2024
11e5676
db test csproj
hallvictoria Apr 2, 2024
a59f90c
Merge branch 'hallvictoria/sdk-bindings' of https://github.com/Azure/…
hallvictoria Apr 2, 2024
45e9066
remove 3.12
hallvictoria Apr 2, 2024
a72e2cc
combined db & e2e test workflow
hallvictoria Apr 4, 2024
cb8c7ce
fixed consumption workflow
hallvictoria Apr 4, 2024
8c146e3
fixed 3.7 tests
hallvictoria Apr 4, 2024
a0920c1
skip all tests
hallvictoria Apr 5, 2024
af10930
renamed registries as constants
hallvictoria Apr 5, 2024
6448eed
add flag as part of FunctionInfo + tests
hallvictoria Apr 5, 2024
03871a8
lint
hallvictoria Apr 5, 2024
c0f5442
added logs (fails until new base)
hallvictoria Apr 5, 2024
2deaad0
Merge branch 'dev' into hallvictoria/sdk-bindings
YunchuWang Apr 8, 2024
40ef29b
lint + base update
Apr 8, 2024
7971498
changing bind_name (fails until exts)
Apr 8, 2024
762e5bd
Revert "changing bind_name (fails until exts)"
hallvictoria Apr 9, 2024
8d74339
is_db property added to PTI
hallvictoria Apr 9, 2024
ec5f38e
fixed test
hallvictoria Apr 9, 2024
06434a2
quick log
hallvictoria Apr 9, 2024
94311f3
better log
hallvictoria Apr 10, 2024
e779583
lint
Apr 10, 2024
7081b0d
refactor FI + pin pip
Apr 10, 2024
37278b9
return cache val immediately
Apr 10, 2024
d565edb
install .[test-db] only for >=3.9
Apr 10, 2024
fc118cb
fixing installation
Apr 10, 2024
1922104
fixing installation pt2
Apr 10, 2024
a9a8fd2
fixing installation pt3
Apr 10, 2024
dbea0bb
sep step for installations
Apr 10, 2024
44a68f5
sep step for installations pt2
Apr 10, 2024
9c3188b
closed if + semicolon
Apr 10, 2024
cb12710
updated refs to base
Apr 10, 2024
d00d6e0
updated refs to blob (rerun later)
Apr 10, 2024
0669c44
update setup.py
hallvictoria Apr 11, 2024
944d8cd
Merge branch 'dev' into hallvictoria/sdk-bindings
hallvictoria Apr 11, 2024
ea9b93d
remove import try/catch
hallvictoria Apr 11, 2024
082d7ef
log bug fix
hallvictoria Apr 11, 2024
f10ccf4
unit tests
hallvictoria Apr 11, 2024
a3316f8
pin pip
hallvictoria Apr 11, 2024
6fb251e
log if base not found
hallvictoria Apr 11, 2024
a7188ba
log delimiters
hallvictoria Apr 11, 2024
fe06530
removed f strings
hallvictoria Apr 11, 2024
a719a91
lint + feedback
hallvictoria Apr 11, 2024
53bcc2e
pydocs + default val
hallvictoria Apr 11, 2024
a798640
get_raw_bindings method
hallvictoria Apr 11, 2024
9eb0959
var names + docs
hallvictoria Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/ISSUE_TEMPLATE/deferred_bindings_bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Python Worker Deferred Bindings Feature Request
description: File a Deferred Bindings bug report
title: "[Bug] Bug Title Here"
labels: ["python", "bug", "deferred-bindings"]
body:
- type: markdown
attributes:
value: |
This form will help you to fill in a bug report for the Azure Functions Python Worker Deferred Bindings feature.

- type: textarea
id: expected-behavior
attributes:
label: Expected Behavior
description: A clear and concise description of what you expected to happen.
placeholder: What should have occurred?

- type: textarea
id: actual-behavior
attributes:
label: Actual Behavior
description: A clear and concise description of what actually happened.
placeholder: What went wrong?

- type: textarea
id: reproduction-steps
attributes:
label: Steps to Reproduce
description: Please provide detailed step-by-step instructions on how to reproduce the bug.
placeholder: |
1. Go to the [specific page or section] in the application.
2. Click on [specific button or link].
3. Scroll down to [specific location].
4. Observe [describe what you see, e.g., an error message or unexpected behavior].
5. Include any additional steps or details that may be relevant.

- type: textarea
id: code-snippet
attributes:
label: Relevant code being tried
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell

- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell

- type: textarea
id: requirements
attributes:
label: requirements.txt file
description: Please copy and paste your requirements.txt file. This will be automatically formatted into code, so no need for backticks.
render: shell

- type: dropdown
id: environment
attributes:
label: Where are you facing this problem?
default: 0
options:
- Local - Core Tools
- Production Environment (explain below)

hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
- type: textarea
id: additional-info
attributes:
label: Additional Information
description: Add any other information about the problem here.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/deferred_bindings_feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Python Worker Deferred Bindings Feature Request
description: File a Deferred Bindings Feature report
title: "Request a feature"
labels: ["python", "feature", "deferred-bindings"]
body:
- type: markdown
attributes:
value: |
This form will help you to fill in a feature request for the Azure Functions Python Worker Deferred Bindings feature.

- type: textarea
id: binding-type
attributes:
label: Binding Type
description: Add information about the binding type.
placeholder: Is this on an existing binding or new binding?

- type: textarea
id: expected-behavior
attributes:
label: Expected Behavior
description: A clear and concise description of what you expected to happen.
placeholder: What should have occurred?

- type: textarea
id: code-snippet
attributes:
label: Relevant sample code snipped
description: Please copy and paste any relevant code snippet of how you want the feature to be used. (This will be automatically formatted into code, so no need for backticks)
render: shell

hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
- type: textarea
id: additional-info
attributes:
label: Additional Information
description: Add any other information about the problem here.
3 changes: 2 additions & 1 deletion .github/Scripts/e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
python -m pytest -q -n auto --dist loadfile --reruns 4 --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/endtoend/test_worker_process_count_functions.py tests/endtoend/test_threadpool_thread_count_functions.py
python -m pytest -q -n auto --dist loadfile --reruns 4 --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append --ignore=tests/endtoend/test_worker_process_count_functions.py --ignore=tests/endtoend/test_threadpool_thread_count_functions.py tests/endtoend
python -m pytest -q -n auto --dist loadfile --reruns 4 --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append --ignore=tests/endtoend/test_worker_process_count_functions.py --ignore=tests/endtoend/test_threadpool_thread_count_functions.py tests/endtoend
python -m pytest -q -n auto --dist loadfile --reruns 4 --instafail --cov=./azure_functions_worker --cov-report xml --cov-branch --cov-append tests/extension_tests/deferred_bindings_tests
1 change: 1 addition & 0 deletions .github/workflows/ci_consumption_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U azure-functions --pre
python -m pip install -U -e .[dev]
python setup.py build
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci_e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ on:
pull_request:
branches: [dev, main, release/*]
schedule:
# Monday to Thursday 3 AM CST build
# Monday to Friday 3 AM CST build
# * is a special character in YAML so you have to quote this string
- cron: "0 8 * * 1,2,3,4"
- cron: "0 8 * * 1,2,3,4,5"

jobs:
build:
Expand Down Expand Up @@ -61,6 +61,9 @@ jobs:
python -m pip install --upgrade pip
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U azure-functions --pre
python -m pip install -U -e .[dev]
if [[ "${{ matrix.python-version }}" != "3.7" && "${{ matrix.python-version }}" != "3.8" ]]; then
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --pre -U -e .[test-deferred-bindings]
fi

# Retry a couple times to avoid certificate issue
retry 5 python setup.py build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_ut_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

python -m pip install --upgrade pip
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple -U azure-functions --pre
python -m pip install -U -e .[dev]
python -m pip install -U -e .[dev]

# Retry a couple times to avoid certificate issue
retry 5 python setup.py build
Expand Down
4 changes: 2 additions & 2 deletions azure_functions_worker/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .meta import has_implicit_output
from .meta import is_trigger_binding, load_binding_registry
from .meta import from_incoming_proto, to_outgoing_proto, \
to_outgoing_param_binding
to_outgoing_param_binding, check_deferred_bindings_enabled
from .out import Out


Expand All @@ -19,5 +19,5 @@
'check_input_type_annotation', 'check_output_type_annotation',
'has_implicit_output',
'from_incoming_proto', 'to_outgoing_proto', 'TraceContext', 'RetryContext',
'to_outgoing_param_binding'
'to_outgoing_param_binding', 'check_deferred_bindings_enabled'
)
2 changes: 2 additions & 0 deletions azure_functions_worker/bindings/datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def from_typed_data(cls, td: protos.TypedData):
val = td.collection_string
elif tt == 'collection_sint64':
val = td.collection_sint64
elif tt == 'model_binding_data':
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
val = td.model_binding_data
elif tt is None:
return None
else:
Expand Down
104 changes: 95 additions & 9 deletions azure_functions_worker/bindings/meta.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import sys
import typing

from .. import protos

from . import datumdef
from . import generic

from .shared_memory_data_transfer import SharedMemoryManager
from ..constants import CUSTOMER_PACKAGES_PATH
from ..logging import logger

PB_TYPE = 'rpc_data'
PB_TYPE_DATA = 'data'
PB_TYPE_RPC_SHARED_MEMORY = 'rpc_shared_memory'
# Base extension supported Python minor version
BASE_EXT_SUPPORTED_PY_MINOR_VERSION = 8

BINDING_REGISTRY = None
DEFERRED_BINDING_REGISTRY = None
deferred_bindings_cache = {}


def load_binding_registry() -> None:
Expand All @@ -25,15 +34,43 @@ def load_binding_registry() -> None:
global BINDING_REGISTRY
BINDING_REGISTRY = func.get_binding_registry()


def get_binding(bind_name: str) -> object:
if BINDING_REGISTRY is None:
# If the BINDING_REGISTRY is None, azure-functions hasn't been
# loaded in properly.
raise AttributeError('BINDING_REGISTRY is None. Sys Path:'
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
f'{sys.path}, Sys Module: {sys.modules},'
f'python-packages Path exists: '
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
f'{os.path.exists(CUSTOMER_PACKAGES_PATH)}.')

# The base extension supports python 3.8+
if sys.version_info.minor >= BASE_EXT_SUPPORTED_PY_MINOR_VERSION:
# Import the base extension
try:
import azurefunctions.extensions.base as clients
global DEFERRED_BINDING_REGISTRY
DEFERRED_BINDING_REGISTRY = clients.get_binding_registry()
except ImportError:
logger.info('Base extension not found. '
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
f'Python version: 3.{sys.version_info.minor}, '
f'Sys path: {sys.path}, '
f'Sys Module: {sys.modules}, '
f'python-packages Path exists: '
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
f'{os.path.exists(CUSTOMER_PACKAGES_PATH)}.')


def get_binding(bind_name: str,
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
is_deferred_binding: typing.Optional[bool] = False)\
-> object:
binding = None
registry = BINDING_REGISTRY
if registry is not None:
binding = registry.get(bind_name)
# Common use case
if binding is None and not is_deferred_binding:
binding = BINDING_REGISTRY.get(bind_name)
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
# Binding is deferred binding
if binding is None and is_deferred_binding:
binding = DEFERRED_BINDING_REGISTRY.get(bind_name)
# Binding is generic
if binding is None:
binding = generic.GenericBinding

return binding


Expand All @@ -42,8 +79,10 @@ def is_trigger_binding(bind_name: str) -> bool:
return binding.has_trigger_support()


def check_input_type_annotation(bind_name: str, pytype: type) -> bool:
binding = get_binding(bind_name)
def check_input_type_annotation(bind_name: str,
pytype: type,
is_deferred_binding: bool) -> bool:
binding = get_binding(bind_name, is_deferred_binding)
return binding.check_input_type_annotation(pytype)


Expand All @@ -68,11 +107,12 @@ def has_implicit_output(bind_name: str) -> bool:

def from_incoming_proto(
binding: str,
is_deferred_binding: bool,
pb: protos.ParameterBinding, *,
pytype: typing.Optional[type],
trigger_metadata: typing.Optional[typing.Dict[str, protos.TypedData]],
shmem_mgr: SharedMemoryManager) -> typing.Any:
binding = get_binding(binding)
binding = get_binding(binding, is_deferred_binding)
if trigger_metadata:
metadata = {
k: datumdef.Datum.from_typed_data(v)
Expand All @@ -93,6 +133,13 @@ def from_incoming_proto(
raise TypeError(f'Unknown ParameterBindingType: {pb_type}')

try:
# if the binding is an sdk type binding
if is_deferred_binding:
return deferred_bindings_decode(binding=binding,
pb=pb,
pytype=pytype,
datum=datum,
metadata=metadata)
return binding.decode(datum, trigger_metadata=metadata)
except NotImplementedError:
# Binding does not support the data.
Expand Down Expand Up @@ -184,3 +231,42 @@ def to_outgoing_param_binding(binding: str, obj: typing.Any, *,
return protos.ParameterBinding(
name=out_name,
data=rpc_val)


def deferred_bindings_decode(binding: typing.Any,
pb: protos.ParameterBinding, *,
pytype: typing.Optional[type],
datum: typing.Any,
metadata: typing.Any):
# This cache holds deferred binding types (ie. BlobClient, ContainerClient)
# That have already been created, so that the worker can reuse the
# Previously created type without creating a new one.
global deferred_bindings_cache

# If cache is empty or key doesn't exist, deferred_binding_type is None
if deferred_bindings_cache.get((pb.name,
pytype,
datum.value.content), None) is not None:
return deferred_bindings_cache.get((pb.name,
pytype,
datum.value.content))
else:
deferred_binding_type = binding.decode(datum,
trigger_metadata=metadata,
pytype=pytype)
deferred_bindings_cache[(pb.name,
pytype,
datum.value.content)] = deferred_binding_type
return deferred_binding_type


def check_deferred_bindings_enabled(param_anno: type,
deferred_bindings_enabled: bool) -> (bool,
bool):
# The first bool represents if deferred bindings is enabled at a fx level
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
# The second represents if the current binding is deferred binding
if (DEFERRED_BINDING_REGISTRY is not None
and DEFERRED_BINDING_REGISTRY.check_supported_type(param_anno)):
return True, True
else:
return deferred_bindings_enabled, False
27 changes: 19 additions & 8 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ async def _handle__invocation_request(self, request):
trigger_metadata = None

args[pb.name] = bindings.from_incoming_proto(
pb_type_info.binding_name, pb,
pb_type_info.binding_name,
pb_type_info.deferred_bindings_enabled,
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
pb,
trigger_metadata=trigger_metadata,
pytype=pb_type_info.pytype,
shmem_mgr=self._shmem_mgr)
Expand Down Expand Up @@ -678,21 +680,30 @@ def index_functions(self, function_path: str):
len(indexed_functions))

if indexed_functions:
fx_metadata_results = loader.process_indexed_function(
self._functions,
indexed_functions)
fx_metadata_results, fx_bindings_logs = (
loader.process_indexed_function(
self._functions,
indexed_functions))

indexed_function_logs: List[str] = []
bindings_info = []
for func in indexed_functions:
fx_bindings = fx_bindings_logs.get(func)
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
for binding in func.get_bindings():
deferred_binding_info = fx_bindings.get(binding.name)\
if fx_bindings.get(binding.name) else ""
bindings_info.append((binding.type, binding.name,
deferred_binding_info))

function_log = "Function Name: {}, Function Binding: {}" \
.format(func.get_function_name(),
[(binding.type, binding.name) for binding in
func.get_bindings()])
.format(func.get_function_name(), bindings_info)
indexed_function_logs.append(function_log)

logger.info(
hallvictoria marked this conversation as resolved.
Show resolved Hide resolved
'Successfully processed FunctionMetadataRequest for '
'functions: %s', " ".join(indexed_function_logs))
'functions: %s. Deferred bindings enabled: %s.', " ".join(
indexed_function_logs),
self._functions.deferred_bindings_enabled())

return fx_metadata_results

Expand Down
Loading
Loading