Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

[BUG] Required property 'type' not found in JSON. Path 'properties.deadLetterWithResourceIdentity.identity' #43658

Open brennfoster opened 6 months ago

brennfoster commented 6 months ago

Library name and version

Azure.ResourceManager.EventGrid 1.0.1

Describe the bug

We can no longer create EventGridDomain Subscriptions because of the error in the title. This seems to have started happening randomly in all environments. I can repro on my local machine as well. This is currently affecting our clients.

It seems to complain about:

DeadLetterWithResourceIdentity = new DeadLetterWithResourceIdentity
{
    Identity = new EventSubscriptionIdentity(),
    DeadLetterDestination = new StorageBlobDeadLetterDestination
    {
        BlobContainerName = _config.DeadLetterContainer,
        ResourceId = new ResourceIdentifier(_config.DeadLetterStorage)
    }
}

This has worked with no issue until today when I noticed that no one is able to create subscriptions due to BadRequest errors. Looking into the logs, it looks like this error started occurring on 04/08/2024. I found the exception was thrown related to the DeadLetter storage account:

Required property 'type' not found in JSON. Path 'properties.deadLetterWithResourceIdentity.identity'

However, there is no way to set the 'type' using the Azure.ResourceManager.EventGrid SDK.

Expected behavior

Successfully creates the subscription with a dead letter storage account attached.

Actual behavior

Fails with error: Required property 'type' not found in JSON. Path 'properties.deadLetterWithResourceIdentity.identity'

Reproduction Steps

var data = new EventGridSubscriptionData
{
    Destination = new WebHookEventSubscriptionDestination
    {
        Endpoint = new Uri(dto.Endpoint),
    },
    RetryPolicy = new EventSubscriptionRetryPolicy
    {
        EventTimeToLiveInMinutes = _config.EventTimeToLiveInMinutes,
    },
    Filter = new EventSubscriptionFilter
    {
        SubjectBeginsWith = subscriptionId,
    },
    DeadLetterWithResourceIdentity = new DeadLetterWithResourceIdentity
    {
        Identity = new EventSubscriptionIdentity(),
        DeadLetterDestination = new StorageBlobDeadLetterDestination
        {
            BlobContainerName = _config.DeadLetterContainer,
            ResourceId = new ResourceIdentifier(_config.DeadLetterStorage)
        }
    }
};

data.Filter.IncludedEventTypes.Add(dto.EventType.ToName());

// Create event subscription
var eventSubscriptionOperation = await eventSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionId, data);

Environment

Azure App Service .NET 7

ArcturusZhang commented 6 months ago

Hi @brennfoster thanks for reporting this.

As far as I could see, if the issue complaining that there should be a type property in properties.deadLetterWithResourceIdentity.identity, taking a look at the class EventSubscriptionIdentity: https://github.com/Azure/azure-sdk-for-net/blob/c508cf060606900a6708d28679bd44b033bdb6e1/sdk/eventgrid/Azure.ResourceManager.EventGrid/src/Generated/Models/EventSubscriptionIdentity.cs#L65 The IdentityType property (which serializes into type in the Json) is settable, and you need to set it according to the error message.

github-actions[bot] commented 6 months ago

Hi @brennfoster. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

brennfoster commented 6 months ago

I set the IdentityType and it is working now, but I don't understand why it all the sudden needed that to be set? It has worked fine without setting that for quite a while now. What changed? There are no version upgrades for the nuget package we are referencing. It's nullable so it seems like it is expecting not to be set.