Skip to content

Commit 1ae733c

Browse files
EvanR-DevEvan Romanhallvictoria
authored
build: recognize collection_model_binding_data for batch inputs (#1655)
* add cmbd * Add * Add * Rm newline * Add tests * Fix cmbd * Fix test * Lint * Rm * Rm * Add back newline * rm ws * Rm list * Rm cmbd from cache * Avoid caching * Keep cmbd check * Add comment * Lint --------- Co-authored-by: Evan Roman <[email protected]> Co-authored-by: hallvictoria <[email protected]>
1 parent 65220bc commit 1ae733c

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

azure_functions_worker/bindings/datumdef.py

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def from_typed_data(cls, td: protos.TypedData):
102102
val = td.collection_sint64
103103
elif tt == 'model_binding_data':
104104
val = td.model_binding_data
105+
elif tt == 'collection_model_binding_data':
106+
val = td.collection_model_binding_data
105107
elif tt is None:
106108
return None
107109
else:

azure_functions_worker/bindings/meta.py

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ def deferred_bindings_decode(binding: typing.Any,
300300
"""
301301
global deferred_bindings_cache
302302

303+
# Only applies to Event Hub and Service Bus - cannot cache
304+
# These types will always produce different content and are not clients
305+
if (datum.type == "collection_model_binding_data"
306+
or datum.value.source == "AzureEventHubsEventData"
307+
or datum.value.source == "AzureServiceBusReceivedMessage"):
308+
return binding.decode(datum,
309+
trigger_metadata=metadata,
310+
pytype=pytype)
311+
303312
if deferred_bindings_cache.get((pb.name,
304313
pytype,
305314
datum.value.content,

tests/extension_tests/deferred_bindings_tests/test_deferred_bindings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def test_deferred_bindings_dual_enabled_log(self):
137137
"is only supported for 3.9+.")
138138
class TestDeferredBindingsHelpers(testutils.AsyncTestCase):
139139

140-
def test_deferred_bindings_enabled_decode(self):
140+
def test_mbd_deferred_bindings_enabled_decode(self):
141141
binding = BlobClientConverter
142142
pb = protos.ParameterBinding(name='test',
143143
data=protos.TypedData(

tests/unittests/test_types.py

+23
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,26 @@ def test_model_binding_data_td_ok(self):
194194
mbd_datum = datumdef.Datum.from_typed_data(mock_mbd)
195195

196196
self.assertEqual(mbd_datum.type, 'model_binding_data')
197+
198+
def test_collection_model_binding_data_datum_ok(self):
199+
sample_mbd = MockMBD(version="1.0",
200+
source="AzureStorageBlobs",
201+
content_type="application/json",
202+
content="{\"Connection\":\"python-worker-tests\","
203+
"\"ContainerName\":\"test-blob\","
204+
"\"BlobName\":\"test.txt\"}")
205+
sample_cmbd = [sample_mbd, sample_mbd]
206+
207+
datum: bind_meta.Datum = bind_meta.Datum(value=sample_cmbd,
208+
type='collection_model_binding_data')
209+
210+
self.assertEqual(datum.value, sample_cmbd)
211+
self.assertEqual(datum.type, "collection_model_binding_data")
212+
213+
def test_collection_model_binding_data_td_ok(self):
214+
mock_cmbd = protos.TypedData(
215+
collection_model_binding_data={'model_binding_data': [{'version': '1.0'}]}
216+
)
217+
cmbd_datum = datumdef.Datum.from_typed_data(mock_cmbd)
218+
219+
self.assertEqual(cmbd_datum.type, 'collection_model_binding_data')

0 commit comments

Comments
 (0)