Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the DefaultProfile parameter raises an error on Az 6.2.0 #15425

Closed
OmriAvissar opened this issue Jul 7, 2021 · 5 comments · Fixed by #15444
Closed

Using the DefaultProfile parameter raises an error on Az 6.2.0 #15425

OmriAvissar opened this issue Jul 7, 2021 · 5 comments · Fixed by #15444
Assignees
Labels
Accounts Issues in Az.Accounts except authentication related bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported P0

Comments

@OmriAvissar
Copy link

Description

Multiple Az cmdlets raise the following error while specifying the DefaultProfile parameter:
Error getting value from 'Tags' on 'Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription'.

Using the same cmdlets with the same account, without specifying DefaultProfile works as expected.

Happens with a user principal/service principal/system-assigned managed identity (I've tried with Azure Functions).

Note that the following is true:

$null -eq (Connect-AzAccount).Context.Subscription.Tags

maybe related to the following entry in the changelog:

Az.Accounts
Added Tags, AuthorizationSource to PSAzureSusbscripiton and added TenantType, DefaultDomain, TenantBrandingLogoUrl, CountryCode to PSAzureTenant [#15220]

Steps to reproduce

$UserName = '...'
$UserPassword = '...'
$UserPasswordSecureString = ConvertTo-SecureString $UserPassword -AsPlainText -Force
$UserPsCredential = [System.Management.Automation.PSCredential]::New($UserName, $UserPasswordSecureString)

$AzureProfile = Connect-AzAccount -Subscription '...' -Credential $UserPsCredential
$AzureContext = $AzureProfile.Context

$SetAzSqlDatabaseParameters = @{
    'ResourceGroupName'             = '...'
    'ServerName'                    = '...'
    'DatabaseName'                  = '...'
    'RequestedServiceObjectiveName' = 'S0'
    'ComputeModel'                  = 'Provisioned'
}

Set-AzSqlDatabase @SetAzSqlDatabaseParameters -DefaultProfile $AzureContext

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     6.2.0                 Az                                  Core,Desk
Script     6.1.0                 Az                                  Core,Desk
Script     5.1.0                 Az                                  Core,Desk

Debug output

OperationStopped: Error getting value from 'Tags' on 'Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription'.

Error output

   HistoryId: -1

Message        : Error getting value from 'Tags' on 'Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription'.
StackTrace     :    at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property,
                 JsonContract& memberContract, Object& memberValue)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract,     
                 JsonProperty containerProperty)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract,     
                 JsonProperty containerProperty)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract
                 collectionContract, JsonProperty containerProperty)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract,     
                 JsonProperty containerProperty)
                    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
                    at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
                    at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
                    at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonConverter[] converters)
                    at Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.ToString(Boolean serializeCache)
                    at Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.ToString()
                    at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object     
                 currentValue)
                    at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
                    at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
                    at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)  
                    at System.Management.Automation.CmdletParameterBinderController.BindNamedParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter)
                    at System.Management.Automation.ParameterBinderController.BindNamedParameters(UInt32 parameterSets, Collection`1 arguments)
                    at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
                    at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
                    at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
                    at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
                    at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
                    at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
                    at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
                    at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
                 commandRedirections, FunctionContext funcContext)
                    at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Exception      : Newtonsoft.Json.JsonSerializationException
InvocationInfo : {}
Line           : Set-AzSqlDatabase @SetAzSqlDatabaseParameters -DefaultProfile $AzureContext
Position       : At line:1 char:1
                 + Set-AzSqlDatabase @SetAzSqlDatabaseParameters -DefaultProfile $AzureC …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1

Message        : Value cannot be null. (Parameter 'value')
StackTrace     :    at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
                    at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
                    at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
                    at Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureSubscriptionExtensions.GetTags(IAzureSubscription subscription)
                    at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
Exception      : System.ArgumentNullException
InvocationInfo : {}
Line           : Set-AzSqlDatabase @SetAzSqlDatabaseParameters -DefaultProfile $AzureContext
Position       : At line:1 char:1
                 + Set-AzSqlDatabase @SetAzSqlDatabaseParameters -DefaultProfile $AzureC …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : -1
@OmriAvissar OmriAvissar added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jul 7, 2021
@ghost ghost added question The issue doesn't require a change to the product in order to be resolved. Most issues start as that customer-reported labels Jul 7, 2021
@OmriAvissar
Copy link
Author

I've tried using Az.Accounts version 2.4.0 instead of 2.5.0.

It seems to work fine.

@dingmeng-xue
Copy link
Member

dingmeng-xue commented Jul 7, 2021

Thanks @OmriAvissar . We will look into this issue with high priority. It should be one regression issue in Az.Accounts 2.5.0

@dingmeng-xue dingmeng-xue added Accounts Issues in Az.Accounts except authentication related bug This issue requires a change to an existing behavior in the product in order to be resolved. P0 and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jul 7, 2021
@misterfoo
Copy link

This is affecting us too. A short-term workaround seems to be adding at least one tag on the subscription, but this definitely seems like a bug.

@dingmeng-xue dingmeng-xue added this to the Jul 2021 (2021-08-03) milestone Jul 8, 2021
@dingmeng-xue dingmeng-xue linked a pull request Jul 9, 2021 that will close this issue
8 tasks
@dingmeng-xue
Copy link
Member

Az 6.2.1 and Az.Accounts 2.5.1 have been released.

msJinLei added a commit to msJinLei/azure-powershell-common that referenced this issue Jul 12, 2021
msJinLei added a commit to msJinLei/azure-powershell that referenced this issue Jul 12, 2021
dingmeng-xue pushed a commit to Azure/azure-powershell-common that referenced this issue Jul 13, 2021
msJinLei added a commit to msJinLei/azure-powershell that referenced this issue Jul 14, 2021
isra-fel pushed a commit that referenced this issue Jul 15, 2021
* Fix access error when subscripiton has no Tags property

- Fix the issue #15425
- Add related test cases

* Polish test name for new Az.Accounts smoke test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accounts Issues in Az.Accounts except authentication related bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported P0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants