Azure / Azure/azure-powershell
Update-AzContainerApp with -JsonFilePath fails if env section contains a boolean
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
I am running a command similar to the following:
```pwsh
Update-AzContainerApp -ResourceGroupName "rg-foo" -Name "app-name" -JsonFilePath app.json
```
The command fails with the error `Update-AzContainerApp_UpdateViaJsonFilePath: The server responded with a Request Error, Status: BadRequest`.
When running debug the body of the error says:
```
"errors": {
"$[0].env[14].value": [
"The JSON value could not be converted to System.String. Path: $[0].env[14].value | LineNumber: 0 | BytePositionInLine: 1862."
]
}
```
Changes the boolean to a string works as expected. I tried a similar thing with the `az containerapp update` and it seems to correctly handle this situation.
### Issue script & Debug output
```PowerShell
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions//resourceGroups//providers/Microsoft.App/containerApps/?api-version=2023-05-01
DEBUG: RequestCreated: /subscriptions//resourceGroups//providers/Microsoft.App/containerApps/?api-version=2023-05-01
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: 11:40:40 AM - [ConfigManager] Got nothing from [DisableInstanceDiscovery], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 11:40:40 AM - [ConfigManager] Got [False] from [EnableLoginByWam], Module = [], Cmdlet = [].
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PATCH
Absolute Uri:
https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.App/containerApps/?api-version=2023-05-01
Headers:
x-ms-unique-id : 173
x-ms-client-request-id : c55a8c07-fd1c-419e-9d5b-e8e381faace0
CommandName : update-AzContainerApp
FullCommandName : Update-AzContainerApp_UpdateViaJsonFilePath
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v12.1.0,PSVersion/v7.5.0,Az.App/1.0.0
Body:
{
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions//resourcegroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/managed-id": {}
}
},
"name": "",
"properties": {
"configuration": {
"ingress": {
"allowInsecure": false,
"customDomains": [
{
"bindingType": "SniEnabled",
"certificateId": "/subscriptions//resourceGroups//providers/Microsoft.App/managedEnvironments/aca-env/certificates/wildcard",
"name": ".domain.io"
}
],
"external": true,
"targetPort": 5000
},
"registries": [
{
"identity": "/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/id-aca",
"server": "acrname.azurecr.io"
}
]
},
"managedEnvironmentId": "/subscriptions//resourceGroups//providers/Microsoft.App/managedEnvironments/aca-env",
"template": {
"containers": [
{
"env": [
{
"name": "ASPNETCORE_URLS",
"value": "http://+:5000"
},
{
"name": "DOTNET_ENVIRONMENT",
"value": "Production"
},
...skipped a few ...
{
"name": "KeyVault__Enabled",
"value": true
}
],
"image": "acrname.azurecr.io/foo/repo:1.964.34286-main",
"name": "name",
"probes": [
],
"resources": {
"cpu": 0.25,
"ephemeralStorage": "1Gi",
"memory": "0.5Gi"
}
}
],
"scale": {
"maxReplicas": 5,
"minReplicas": 2
}
},
"workloadProfileName": "Consumption"
}
}
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-ratelimit-remaining-subscription-resource-requests: 699
X-Powered-By : ASP.NET
x-ms-request-id : d2d0d65e-a932-42db-a05b-0f919780e8f4
x-ms-correlation-request-id : d2d0d65e-a932-42db-a05b-0f919780e8f4
x-ms-routing-request-id : AUSTRALIACENTRAL:20250218T014034Z:d2d0d65e-a932-42db-a05b-0f919780e8f4
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
X-Cache : CONFIG_NOCACHE
X-MSEdge-Ref : Ref A: C4229B6B70E540B88518DE50EBEF31B9 Ref B: SYD03EDGE0808 Ref C: 2025-02-18T01:40:33Z
Date : Tue, 18 Feb 2025 01:40:33 GMT
Body:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$[0].env[14].value": [
"The JSON value could not be converted to System.String. Path: $[0].env[14].value | LineNumber: 0 | BytePositionInLine: 1862."
]
},
"traceId": "00-22ec5a57d36e351afd6045a24cbc60a7-b79799a3453187a1-01"
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: CmdletProcessRecordEnd:
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 3.0.2 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 1.0.0 Az.App {Disable-AzContainerAppRevision, Enable-AzContainerAppRevision, Get-AzContainerApp, Get-AzContainerAppAuthConfig…}
```
### Error output
```PowerShell
Message : The server responded with a Request Error, Status: BadRequest
StackTrace :
Exception : Microsoft.Azure.PowerShell.Cmdlets.App.Runtime.RestException`1[Microsoft.Azure.PowerShell.Cmdlets.App.Models.IDefaultErrorResponse]
InvocationInfo : {Update-AzContainerApp_UpdateViaJsonString}
Line : $updateResult = Update-AzContainerApp `
Position : At line:21 char:9
+ $updateResult = Update-AzContainerApp `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 1
```
Contributor guide
Assessment
This issue has not been assessed yet.