Skip to content

'list' object has no attribute 'get_body' in EventHub trigger

Hanzhang Zeng edited this page Jun 22, 2020 · 5 revisions

Background

Recently, we upgraded the function host version v2: 2.0.13351 => 2.0.13907 v3: 3.0.13353 => 3.0.13901

This upgrades the Python worker from 1.0.3 to 1.1.1. In Python worker release 1.0.4, we fix the function.json "cardinality"="many" handling for EventHub triggers.

When setting "cardinality"="many", the Python handler signature should accept a list of events instead of a single one.

from typing import List
import azure.functions as func

def main(events: List[func.EventHubEvent]):

Affects on Python Functions Applications

Some customers may be unaware of the "cardinality"="many" setting in their function.json file, and if the EventHub trigger only handles a single event, this will BREAK.

import azure.functions as func

def main(event: func.EventHubEvent):

Since the event parameter now has a proper list of events, instead of a single event.

How To Mitigate

In EventHub triggers function.json, change the cardinality to one. Or change the EventHub trigger to process multiple events in one go. from

def main(event: func.EventHubEvent):
    event.get_body()

to

def main(events: List[func.EventHubEvent]):
    for event in events:
        event.get_body()

Sorry for the inconvenience, if you have more questions related to this issue, please let me know and comment below.