Skip to content

build: recognize collection_model_binding_data for batch inputs #1655

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

Merged
merged 21 commits into from
Mar 31, 2025
2 changes: 2 additions & 0 deletions azure_functions_worker/bindings/datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def from_typed_data(cls, td: protos.TypedData):
val = td.collection_sint64
elif tt == 'model_binding_data':
val = td.model_binding_data
elif tt == 'collection_model_binding_data':
val = td.collection_model_binding_data
elif tt is None:
return None
else:
Expand Down
9 changes: 9 additions & 0 deletions azure_functions_worker/bindings/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ def deferred_bindings_decode(binding: typing.Any,
"""
global deferred_bindings_cache

# Only applies to Event Hub and Service Bus - cannot cache
# These types will always produce different content and are not clients
if (datum.type == "collection_model_binding_data"
or datum.value.source == "AzureEventHubsEventData"
or datum.value.source == "AzureServiceBusReceivedMessage"):
return binding.decode(datum,
trigger_metadata=metadata,
pytype=pytype)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Improvement suggestion:

validSources = {
"AzureEventHubsEventData",
"AzureServiceBusReceivedMessage"
}

if datum.type == "collection_model_binding_data" or datum.value.source in valid_sources:
return binding.decode(datum, trigger_metadata=metadata, pytype=pytype)

Also, can type can be enum in your datum model? That will avoid the string comparisons and improve the codebae as less strings constant will flow.

if deferred_bindings_cache.get((pb.name,
pytype,
datum.value.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def test_deferred_bindings_dual_enabled_log(self):
"is only supported for 3.9+.")
class TestDeferredBindingsHelpers(testutils.AsyncTestCase):

def test_deferred_bindings_enabled_decode(self):
def test_mbd_deferred_bindings_enabled_decode(self):
binding = BlobClientConverter
pb = protos.ParameterBinding(name='test',
data=protos.TypedData(
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,26 @@ def test_model_binding_data_td_ok(self):
mbd_datum = datumdef.Datum.from_typed_data(mock_mbd)

self.assertEqual(mbd_datum.type, 'model_binding_data')

def test_collection_model_binding_data_datum_ok(self):
sample_mbd = MockMBD(version="1.0",
source="AzureStorageBlobs",
content_type="application/json",
content="{\"Connection\":\"python-worker-tests\","
"\"ContainerName\":\"test-blob\","
"\"BlobName\":\"test.txt\"}")
sample_cmbd = [sample_mbd, sample_mbd]

datum: bind_meta.Datum = bind_meta.Datum(value=sample_cmbd,
type='collection_model_binding_data')

self.assertEqual(datum.value, sample_cmbd)
self.assertEqual(datum.type, "collection_model_binding_data")

def test_collection_model_binding_data_td_ok(self):
mock_cmbd = protos.TypedData(
collection_model_binding_data={'model_binding_data': [{'version': '1.0'}]}
)
cmbd_datum = datumdef.Datum.from_typed_data(mock_cmbd)

self.assertEqual(cmbd_datum.type, 'collection_model_binding_data')
Loading