azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[QUERY] SQL query eventgridevent error after migrating

Open MikkelGlerup opened this issue 2 years ago • 7 comments
trafficstars

Library name and version

Azure.Messaging.EventGrid 4.13.0

Query/Question

Before moving to Azure.Messaging we had a HttpTrigger which would make use of bindings to fetch EventGridEvent via Microsoft.Azure.Webjobs.CosmosDBAttribute SQL query, like so:

[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feedbacks//{itemId}")] HttpRequest req, Guid itemId, [CosmosDB( databaseName:"events", containerName:"log", Connection ="CosmosConnection", SqlQuery = "SELECT * FROM c WHERE c.data.id = {itemId} ORDER BY c._ts DESC" )] IEnumerable<EventGridEvent> feedbackEvents, ILogger log)

However after moving we're now getting the following error:

System.Private.CoreLib: Exception while executing function: ScheduleHandler. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'feedbackEvents'. Newtonsoft.Json: Unable to find a constructor to use for type Azure.Messaging.EventGrid.EventGridEvent. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '[0].Type', line 1, po

My question is have Azure.Messaging.EventGrid gotten rid of being able to fetch EventGridEvents like I wrote, or am I doing something completly wrong?

Environment

.NET 6 Azure Functions Runtime v4 Visual Studio 2022 version 17.4.3

MikkelGlerup avatar Jan 27 '23 14:01 MikkelGlerup

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Jan 27 '23 16:01 jsquire

Hi @MikkelGlerup, It looks like you are trying to use the new EventGridEvent type with an HttpTrigger. This won't work as the HttpTrigger doesn't know about the new model so it ends up using the NewtonSoft deserialization to attempt to construct the model. If you instead use the EventGrid trigger included in the Event Grid WebJobs extension, then things should work.

Samples can be found here.

JoshLove-msft avatar Jan 30 '23 20:01 JoshLove-msft

Hi @MikkelGlerup. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Jan 30 '23 20:01 ghost

/unresolve

MikkelGlerup avatar Feb 03 '23 09:02 MikkelGlerup

Hello @JoshLove-msft You're writing that this is happening because we use a HttpTrigger instead of an EventGridTrigger, and sadly switching around to using EventGridTrigger would require quite a bit of restructiring of our function.

However prior to updating from the now deprecated Microsoft.Azure.Eventgrid we were able to make use of Microsoft.Azure.EventGrid.Models to deserialize the event in the HttpTrigger.

Is this just a feature that has been completely removed then?

MikkelGlerup avatar Feb 03 '23 10:02 MikkelGlerup

Correct, the EventGridEvent model in Azure.Messaging.EventGrid does not integrate with NewtonSoft so it cannot be deserialized automatically in the same way that the legacy model can.

JoshLove-msft avatar Feb 08 '23 20:02 JoshLove-msft

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

ghost avatar Feb 16 '23 02:02 ghost