Azure / Azure/azure-functions-host

JSON deserialization fails in binding expression for EventHubTrigger with cardinality set to "many"

Open
#8,440 2 comments 0 reactions 2 assignees Claimed by @brettsam View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

## Context ##

I'm using a binding expression in an output-binding (in my case blob") that relies on JSON deserialisation (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#json-payloads).

## Works as documented for `cardinality: one` ##

#### **`function.json`**
```json
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "eventHubTrigger",
"name": "source",
"direction": "in",
"eventHubName": "",
"connection": "CN_CONNECTION_STRING",
"cardinality": "one",
"consumerGroup": "$Default"
},
{
"type": "blob",
"name": "sink",
"path": "/{resource}",
"connection": "CONTAINER_CONNECTION_STRING",
"direction": "out"
}
]
}
```

#### **`__init__.py`**
```python
import azure.functions as func

def main(source: func.EventHubEvent, sink: func.Out[str]):
body = source.get_body()
sink.set(body)
```

#### **payload**
```json
{ "resource": "my_resource" }
```

This works as documented: An output blob is created with the name set to whatever the value is for `resource` in the payload.

## Breaks for `cardinality: many` ##

The problem arises when I change cardinality to "many" (for performance reasons):

#### **`function.json`**
```json
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "eventHubTrigger",
"name": "source",
"direction": "in",
"eventHubName": "",
"connection": "CN_CONNECTION_STRING",
"cardinality": "many",
"consumerGroup": "$Default"
},
{
"type": "blob",
"name": "sink",
"path": "/{resource}",
"connection": "CONTAINER_CONNECTION_STRING",
"direction": "out"
}
]
}
```

#### **`__init__.py`**
```python
import azure.functions as func
from typing import List

def main(source: List[func.EventHubEvent], sink: func.Out[str]):
for event in source:
body = event.get_body()
sink.set(body)
```

#### **payload**
_Same as above_

When the function is invoked, and exception is raised: `No value for named parameter 'resource'`.

## Expected ##
I expected an output blob to be created for every message in the batched payload.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.