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

[BUG] Unable to update existing automation assets using CreateOrUpdateAsync

Open davecader opened this issue 2 years ago • 1 comments

Library name and version

Azure.ResourceManager.Automation 1.0

Describe the bug

I am observing an ArgumentNullException when attempting to update an existing automation asset (i.e. variable, connection, schedule, etc.) using any of the CreateOrUpdateAsync/CreateOrUpdate methods. I can use this method to create new assets without an problems, but it invariably fails with existing assets.

Please see the following exception details:

System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: resourceId Source=Azure.Core StackTrace: at Azure.Core.Argument.AssertNotNullOrEmpty(String value, String name) at Azure.Core.ResourceIdentifier..ctor(String resourceId) at Azure.ResourceManager.Automation.AutomationVariableData.DeserializeAutomationVariableData(JsonElement element) at Azure.ResourceManager.Automation.VariableRestOperations.<CreateOrUpdateAsync>d__6.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Azure.ResourceManager.Automation.AutomationVariableCollection.<CreateOrUpdateAsync>d__5.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Kelverion.RunbookStudio.Cloud.Core.AutomationVariableCollectionClient.<CreateCoreAsync>d__3.MoveNext() in C:\Users\DavidCader\source\repos\app-automation-console\Src\Kelverion.RunbookStudio.Cloud\Core\AutomationVariableCollectionClient.cs:line 28 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Kelverion.RunbookStudio.Cloud.Core.AutomationCollectionClientBase`1.<CreateAsync>d__9.MoveNext() in C:\Users\DavidCader\source\repos\app-automation-console\Src\Kelverion.RunbookStudio.Cloud\Core\AutomationCollectionClientBase.cs:line 59

This exception was originally thrown at this call stack: Azure.Core.Argument.AssertNotNullOrEmpty(string, string) Azure.Core.ResourceIdentifier.ResourceIdentifier(string) Azure.ResourceManager.Automation.AutomationVariableData.DeserializeAutomationVariableData(System.Text.Json.JsonElement) Azure.ResourceManager.Automation.VariableRestOperations.CreateOrUpdateAsync(string, string, string, string, Azure.ResourceManager.Automation.Models.AutomationVariableCreateOrUpdateContent, System.Threading.CancellationToken) Azure.ResourceManager.Automation.AutomationVariableCollection.CreateOrUpdateAsync(Azure.WaitUntil, string, Azure.ResourceManager.Automation.Models.AutomationVariableCreateOrUpdateContent, System.Threading.CancellationToken) Kelverion.RunbookStudio.Cloud.Core.AutomationVariableCollectionClient.CreateCoreAsync(Kelverion.RunbookStudio.Models.VariableAsset) in AutomationVariableCollectionClient.cs Kelverion.RunbookStudio.Cloud.Core.AutomationCollectionClientBase<TLocalType>.CreateAsync(TLocalType) in AutomationCollectionClientBase.cs

Expected behavior

You should be able to update automation assets using the CreateOrUpdateAsync methods.

Actual behavior

An ArgumentNullException (Value cannot be null. Parameter anme: resourceId) exception is observed.

Reproduction Steps

async Task UpdateVariableAssetTest(ArmClient armClient, ResourceIdentifier automationAccountId, string variableName, string value) { AutomationAccountResource automationAccountResource = armClient.GetAutomationAccountResource(automationAccountId); AutomationVariableCollection varialbes = automationAccountResource.GetAutomationVariables();

var content = new AutomationVariableCreateOrUpdateContent("<AssetName>")
{
    Description = "This is a test",
    IsEncrypted = false,
    Value = value,
};

await varialbes.CreateOrUpdateAsync(WaitUntil.Completed, variableName, content);

}

Environment

Windows 10, .NET Framework 4.8

davecader avatar Feb 16 '23 16:02 davecader

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

jsquire avatar Feb 16 '23 16:02 jsquire

Hi @davecader thanks for this issue!

By checking the stack trace at Azure.Core.Argument.AssertNotNullOrEmpty(String value, String name) at Azure.Core.ResourceIdentifier..ctor(String resourceId) at Azure.ResourceManager.Automation.AutomationVariableData.DeserializeAutomationVariableData(JsonElement element) We noticed that this happens when deserializing the response into AutomationVariableData, and the SDK gets a null value for the property id which is unacceptable because the SDK will always requires a value for Id. We think this is a violation of ARM convention, and we will call the corresponding service team to take a look at this issue as soon as possible. In the meantime, could you please enable content logging for your SDK so that we could see the actual raw response and confirm if the service really returns a null value for id? You could do that by following this document: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md#logging

ArcturusZhang avatar Feb 18 '23 02:02 ArcturusZhang

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jaspkaur28, @omairabdullah.

Issue Details

Library name and version

Azure.ResourceManager.Automation 1.0

Describe the bug

I am observing an ArgumentNullException when attempting to update an existing automation asset (i.e. variable, connection, schedule, etc.) using any of the CreateOrUpdateAsync/CreateOrUpdate methods. I can use this method to create new assets without an problems, but it invariably fails with existing assets.

Please see the following exception details:

System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: resourceId Source=Azure.Core StackTrace: at Azure.Core.Argument.AssertNotNullOrEmpty(String value, String name) at Azure.Core.ResourceIdentifier..ctor(String resourceId) at Azure.ResourceManager.Automation.AutomationVariableData.DeserializeAutomationVariableData(JsonElement element) at Azure.ResourceManager.Automation.VariableRestOperations.<CreateOrUpdateAsync>d__6.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Azure.ResourceManager.Automation.AutomationVariableCollection.<CreateOrUpdateAsync>d__5.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Kelverion.RunbookStudio.Cloud.Core.AutomationVariableCollectionClient.<CreateCoreAsync>d__3.MoveNext() in C:\Users\DavidCader\source\repos\app-automation-console\Src\Kelverion.RunbookStudio.Cloud\Core\AutomationVariableCollectionClient.cs:line 28 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Kelverion.RunbookStudio.Cloud.Core.AutomationCollectionClientBase`1.<CreateAsync>d__9.MoveNext() in C:\Users\DavidCader\source\repos\app-automation-console\Src\Kelverion.RunbookStudio.Cloud\Core\AutomationCollectionClientBase.cs:line 59

This exception was originally thrown at this call stack: Azure.Core.Argument.AssertNotNullOrEmpty(string, string) Azure.Core.ResourceIdentifier.ResourceIdentifier(string) Azure.ResourceManager.Automation.AutomationVariableData.DeserializeAutomationVariableData(System.Text.Json.JsonElement) Azure.ResourceManager.Automation.VariableRestOperations.CreateOrUpdateAsync(string, string, string, string, Azure.ResourceManager.Automation.Models.AutomationVariableCreateOrUpdateContent, System.Threading.CancellationToken) Azure.ResourceManager.Automation.AutomationVariableCollection.CreateOrUpdateAsync(Azure.WaitUntil, string, Azure.ResourceManager.Automation.Models.AutomationVariableCreateOrUpdateContent, System.Threading.CancellationToken) Kelverion.RunbookStudio.Cloud.Core.AutomationVariableCollectionClient.CreateCoreAsync(Kelverion.RunbookStudio.Models.VariableAsset) in AutomationVariableCollectionClient.cs Kelverion.RunbookStudio.Cloud.Core.AutomationCollectionClientBase<TLocalType>.CreateAsync(TLocalType) in AutomationCollectionClientBase.cs

Expected behavior

You should be able to update automation assets using the CreateOrUpdateAsync methods.

Actual behavior

An ArgumentNullException (Value cannot be null. Parameter anme: resourceId) exception is observed.

Reproduction Steps

async Task UpdateVariableAssetTest(ArmClient armClient, ResourceIdentifier automationAccountId, string variableName, string value) { AutomationAccountResource automationAccountResource = armClient.GetAutomationAccountResource(automationAccountId); AutomationVariableCollection varialbes = automationAccountResource.GetAutomationVariables();

var content = new AutomationVariableCreateOrUpdateContent("<AssetName>")
{
    Description = "This is a test",
    IsEncrypted = false,
    Value = value,
};

await varialbes.CreateOrUpdateAsync(WaitUntil.Completed, variableName, content);

}

Environment

Windows 10, .NET Framework 4.8

Author: davecader
Assignees: xboxeer
Labels:

Automation, Service Attention, Mgmt, customer-reported, question, needs-team-attention

Milestone: -

ghost avatar Feb 18 '23 02:02 ghost

I have enabled diagnostics with content logging as requested, but I'm not seeing details of the response in the logs. This is all that I get related to the CreateOrUpdate method call.

=== Token Acquisition finished successfully:

False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Pro [2023-02-21 17:27:38Z - 8d202c01-b214-4d3a-9539-73ea7fe72939] AT expiration time: 2023-02-21 6:36:09 PM +00:00, scopes: https://management.azure.com//user_impersonation https://management.azure.com//.default. source: IdentityProvider False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Pro [2023-02-21 17:27:38Z - 8d202c01-b214-4d3a-9539-73ea7fe72939] Fetched access token from host login.microsoftonline.com. InteractiveBrowserCredential.GetToken succeeded. Scopes: [ https://management.azure.com//.default ] ParentRequestId: d5207853-43d8-4eda-92c5-a7ec501ed813 ExpiresOn: 2023-02-21T18:36:09.7956055+00:00 Request [d5207853-43d8-4eda-92c5-a7ec501ed813] PUT https://management.azure.com/subscriptions/60da6add-91e2-4da1-a6fb-7a417d88c042/resourceGroups/Kelverion_Canada_East/providers/Microsoft.Automation/automationAccounts/DC-TEST2/variables/String5?api-version=2020-01-13-preview Accept:application/json Content-Type:application/json x-ms-client-request-id:d5207853-43d8-4eda-92c5-a7ec501ed813 x-ms-return-client-request-id:true User-Agent:azsdk-net-ResourceManager.Automation/1.0.1 (.NET Framework 4.8.4614.0; Microsoft Windows 10.0.19045 ) Authorization:REDACTED client assembly: Azure.ResourceManager Response [d5207853-43d8-4eda-92c5-a7ec501ed813] 200 OK (00.6s) Pragma:no-cache x-ms-request-id:d5207853-43d8-4eda-92c5-a7ec501ed813 x-ms-ratelimit-remaining-subscription-writes:REDACTED x-ms-correlation-request-id:REDACTED x-ms-routing-request-id:REDACTED Strict-Transport-Security:REDACTED X-Content-Type-Options:REDACTED Content-Length:256 Cache-Control:no-cache Content-Type:application/json; charset=utf-8 Date:Tue, 21 Feb 2023 17:27:30 GMT Expires:-1 Server:Microsoft-HTTPAPI/2.0

davecader avatar Feb 21 '23 17:02 davecader

Also hitting this issue. Any updates?

sambetts avatar Apr 12 '24 11:04 sambetts

Quick update: variables get created, just reading the server response throws this exception. Ergo, this workaround works:

var varWeeksToKeep = new AutomationVariableCreateOrUpdateContent(CONFIG_PARAM_NAME_WEEKS_TO_KEEP)
{
    Value = "4", 
    IsEncrypted = false,
    Description = "Number of weeks to keep data"
};

var variables = automationAccount.GetAutomationVariables();
try
{
    await variables.CreateOrUpdateAsync(WaitUntil.Completed, CONFIG_PARAM_NAME_WEEKS_TO_KEEP, varWeeksToKeep );
}
catch (ArgumentNullException)
{
    // Ignore. https://github.com/Azure/azure-sdk-for-net/issues/34261
}

The variable appears. Not ideal but still better than nothing.

// Sam

sambetts avatar Apr 15 '24 13:04 sambetts