Azure / Azure/azure-functions-python-worker

[Bug] Testing Batched Event Hub Trigger

Open
#1,524 12 comments 0 reactions 1 assignee Assigned to @JAdluri View on GitHub
area:python-functions bug python-sdk
Dominant language
Python
Stars
357
Forks
116
Avg merge
32m
Merged PRs (30d)
1

Description

### Expected Behavior

1. Triggering an event hub triggered function with cardinality MANY locally via HTTP should pass a list of EventHubEvent to the function.
2. Type hints should not influence loading the azure functions.
3. The new event hub emulator should work with the event hub trigger.

### Actual Behavior

1. Triggering an event hub triggered function with cardinality MANY locally via HTTP passes a single EventHubEvent to the function, but wraps the event body in a list.
+ Triggering the function with a request body `{'input': {'some': 'awesome', 'event': 'body'}}` gives an EventHubEvent with the body `[{'some': 'awesome', 'event': 'body'}]`.
+ Posting multiple events `{'input': [{'some': 'awesome', 'event': 'body'}, {'some': 'other', 'event': 'body'}]}` gives a nested list `[[{'some': 'awesome', 'event': 'body'}, {'some': 'other', 'event': 'body'}]]`

I had to write a check to convert single events into a list in order to test my function locally and had to extract all the functionality in a seperate function which is called from my function so I can test it with batches. This solution is not pretty, but fine.

2. Unfortunately, the type hinting breaks loading the azure function. I dont know why, but proper typing
`def batch_triggered(events: func.EventHubEvent | List[func.EventHubEvent]):` prohibits the function from being loaded. It is found, but not loaded. Doing `def batch_triggered(events: List[func.EventHubEvent]):` or `def batch_triggered(events: func.EventHubEvent):` is fine, though.

3. I also tried to use the new event hub emulator instead of triggering the function via HTTP for my tests, but the event hub always refuses the connection. I don't know, if this is an issue of the emulator or the worker. I'm raising this issue here, because the emulator does work with the current version of the python SDK.

### Steps to Reproduce

HTTP-Trigger Issue
1. Set cardinality of event hub triggered function (v2) to many.
2. Trigger the function via POST request

Typing Issue
1. Type hint event hub triggered function like `def batch_triggered(events: func.EventHubEvent | List[func.EventHubEvent]):`
2. Start the python workers docker image

Event Hub Emulator Issue
1. Write docker compose running an event hub emulator and the function worker docker image (https://learn.microsoft.com/en-us/azure/event-hubs/test-locally-with-event-hub-emulator?tabs=docker-linux-container#run-the-emulator)
2. Add healthcheck to event hub, because function app starts way faster than the emulator and fails starting if emulator's not ready
3. Make sure the event hub triggered function is not disabled.
4. Set environment variable with emulators connection string (https://learn.microsoft.com/en-us/azure/event-hubs/test-locally-with-event-hub-emulator?tabs=docker-linux-container#interact-with-the-emulator). Pass the name of the environment variable as event hub triggers `connection` parameter.
5. `docker compose up`. Function startup will fail, becasue event hub emulator refuses the connection
6. Connect to the event hub via python SDK with the same connection string. Sending and receiving events will work.

### Relevant code being tried

_No response_

### Relevant log output

_No response_

### requirements.txt file

_No response_

### Where are you facing this problem?

Local - Core Tools

### Function app name

_No response_

### Additional Information

_No response_

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.