Skip to content

[Bug] Event Grid Output not working with Namespace Topics #1642

@samaksh-khatri-simform

Description

@samaksh-khatri-simform

Expected Behavior

The event grid output binding should have published the event to the namespace topic.

Actual Behavior

I have created a Namespace Topic in Event Grid and defined an output binding for Event Grid for an Azure Function in Python that has an HTTP Trigger.

When trying to send an event, the worker throws an error of "Unknown api version" for the namespace topic Endpoint.

Here is the code for the Azure Function

@app.function_name(name="EventGridOutput")
@app.event_grid_output(
    arg_name="outputEvent",
    topic_endpoint_uri="MyEventGridTopicUriSetting",
    topic_key_setting="MyEventGridTopicKeySetting",
)
@app.route(route="test/event", auth_level=func.AuthLevel.ANONYMOUS)
async def test(
    req: func.HttpRequest, outputEvent: func.Out[func.EventGridOutputEvent]
) -> func.HttpResponse:
    body = req.get_json()
    outputEvent.set(
        func.EventGridOutputEvent(
            id="test-id",
            data=body,
            subject="test-subject",
            event_type="test-event-1",
            event_time=datetime.datetime.now(datetime.timezone.utc),
            data_version="1.0",
        )
    )
    return func.HttpResponse(body=json.dumps(body), status_code=200)

The endpoint is defined as https://<namespace>.<region>.eventgrid.azure.net/topics/<topic-name>:publish?api-version=2023-06-01-preview as per the documentation

Here is the error log

[2025-02-17T13:33:39.136Z] Executed 'Functions.EventGridOutput' (Failed, Id=afba7a9a-cd3a-4799-8691-a8e1486e6007, Duration=9564ms)
[2025-02-17T13:33:39.136Z] System.Private.CoreLib: Exception while executing function: Functions.EventGridOutput. Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:. Azure.Messaging.EventGrid: Unknown api version
[2025-02-17T13:33:39.136Z] Status: 400 (Bad Request)
[2025-02-17T13:33:39.136Z] ErrorCode: ArgumentInvalid
[2025-02-17T13:33:39.136Z] 
[2025-02-17T13:33:39.136Z] Content:
[2025-02-17T13:33:39.136Z] {"error":{"code":"ArgumentInvalid","message":"Unknown api version","timestamp_utc":"2025-02-17T13:33:38.952263956+00:00","tracking_id":"97E4C477-71A9-4516-B44A-72935B15DD4A"}}
[2025-02-17T13:33:39.136Z] 
[2025-02-17T13:33:39.136Z] Headers:
[2025-02-17T13:33:39.136Z] broker-errorcode: REDACTED
[2025-02-17T13:33:39.137Z] Date: Mon, 17 Feb 2025 13:33:38 GMT
[2025-02-17T13:33:39.137Z] Content-Length: 175
[2025-02-17T13:33:39.137Z] Content-Type: application/json; charset=utf-8
[2025-02-17T13:33:39.137Z] .

This is working totally fine if I am using a topic that is not under a namespace and if I follow the documentation to publish an event in a namespace topic using Azure CLI and curl command, it works too with the same endpoint.

For api version of the topic endpoint I tried different values such as 2025-02-15 and 2018-01-01 but nothing works. Defining the endpoint without the api-version param doesn't work either

Steps to Reproduce

No response

Relevant code being tried

@app.function_name(name="EventGridOutput")
@app.event_grid_output(
    arg_name="outputEvent",
    topic_endpoint_uri="MyEventGridTopicUriSetting",
    topic_key_setting="MyEventGridTopicKeySetting",
)
@app.route(route="test/event", auth_level=func.AuthLevel.ANONYMOUS)
async def test(
    req: func.HttpRequest, outputEvent: func.Out[func.EventGridOutputEvent]
) -> func.HttpResponse:
    body = req.get_json()
    outputEvent.set(
        func.EventGridOutputEvent(
            id="test-id",
            data=body,
            subject="test-subject",
            event_type="test-event-1",
            event_time=datetime.datetime.now(datetime.timezone.utc),
            data_version="1.0",
        )
    )
    return func.HttpResponse(body=json.dumps(body), status_code=200)

Relevant log output

requirements.txt file

Where are you facing this problem?

Local - Core Tools

Function app name

No response

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions