Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

az storage entity insert forcing a string to int32 #30377

Open JackBruceShell opened 4 days ago

JackBruceShell commented 4 days ago

Describe the bug

String is being sent as a "property" to be inserted into a property, when viewing in the portal the string "0152" has been converted to type int32 and shows "052"

Related command

    az storage entity insert --if-exists merge --entity PartitionKey=$partitionKey RowKey=$rowKey $property --table-name $tableName --account-name $storageAccountName --auth-mode login

Errors

No errors, just incorrect behaviour

Issue script & Debug output

Script:

az account set --subscription XXX $path="./testFile.json" $object = Get-Content $path | ConvertFrom-Json $storageAccountName = "XXX" $tableName = "XXX" for ($i = 0; $i -lt $object.Count; $i++) { $obj = $object[$i] $partitionKey = $obj.PartitionKey $rowKey = $obj.RowKey $obj.PSObject.Properties.Remove('PartitionKey') $obj.PSObject.Properties.Remove('RowKey') Write-Host "PartitionKey: $partitionKey" Write-Host "RowKey: $rowKey" Write-Host "Modified Object:" $obj | ConvertTo-Json -Depth 5 $ht2 = @{} $obj.psobject.properties | Foreach { $ht2[$.Name] = $.Value } Write-Host "ht2: $ht2" Write-Host "Object: $obj"

foreach ($entry in $ht2.GetEnumerator()) {
    $key = $entry.Key
    $value = $entry.Value
    $valueType = $value.GetType()
    ## Check value of the property
    Write-Host "Value type: $value"
    Write-Host $value.GetType()

    $property = $entry.Key + "=" + $entry.Value
    Write-Host "Property: $property"
    # Write-Host $property
    az storage entity insert --if-exists merge --entity PartitionKey=$partitionKey RowKey=$rowKey $property --table-name $tableName --account-name $storageAccountName --auth-mode login
}

}

Output: PartitionKey: C2S_CROSS_GSAP_OU_MAP RowKey: DEC-0154 Modified Object: { "CROSS_OUCode": "DEC", "CROSS_TPPCode": "0154", "CROSS_SSN": "", "GSAP_OUCode": "DE01" } ht2: System.Collections.Hashtable Object: @{CROSS_OUCode=DEC; CROSS_TPPCode=0154; CROSS_SSN=; GSAP_OUCode=DE01} Value type: 0154 System.String Property: CROSS_TPPCode=0154 { "date": "2024-11-18T16:20:12+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A12.3183423Z'\"", "version": "2019-02-02" } Value type: DEC System.String Property: CROSS_OUCode=DEC { "date": "2024-11-18T16:20:13+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A13.7894865Z'\"", "version": "2019-02-02" } Value type: System.String Property: CROSS_SSN= { "date": "2024-11-18T16:20:14+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A15.148696Z'\"", "version": "2019-02-02" } Value type: DE01 System.String Property: GSAP_OUCode=DE01 { "date": "2024-11-18T16:20:16+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A17.0475922Z'\"", "version": "2019-02-02" } PartitionKey: C2S_CROSS_GSAP_OU_MAP RowKey: DEF-0154 Modified Object: { "CROSS_OUCode": "DEF", "CROSS_TPPCode": "0154", "CROSS_SSN": "", "GSAP_OUCode": "DE01" } ht2: System.Collections.Hashtable Object: @{CROSS_OUCode=DEF; CROSS_TPPCode=0154; CROSS_SSN=; GSAP_OUCode=DE01} Value type: 0154 System.String Property: CROSS_TPPCode=0154 { "date": "2024-11-18T16:20:18+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A18.8605368Z'\"", "version": "2019-02-02" } Value type: DEF System.String Property: CROSS_OUCode=DEF { "date": "2024-11-18T16:20:19+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A20.0078691Z'\"", "version": "2019-02-02" } Value type: System.String Property: CROSS_SSN= { "date": "2024-11-18T16:20:20+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A21.5189903Z'\"", "version": "2019-02-02" } Value type: DE01 System.String Property: GSAP_OUCode=DE01 { "date": "2024-11-18T16:20:22+00:00", "etag": "W/\"datetime'2024-11-18T16%3A20%3A22.9781421Z'\"", "version": "2019-02-02" }

File input: [ { "PartitionKey": "C2S_CROSS_GSAP_OU_MAP", "RowKey": "DEC-0154", "CROSS_OUCode": "DEC", "CROSS_TPPCode": "0154", "CROSS_SSN": "", "GSAP_OUCode": "DE01" }, { "PartitionKey": "C2S_CROSS_GSAP_OU_MAP", "RowKey": "DEF-0154", "CROSS_OUCode": "DEF", "CROSS_TPPCode": "0154", "CROSS_SSN": "", "GSAP_OUCode": "DE01" } ]

The field in question that is failing is "CROSS_TPPCode".

Expected behavior

String is entered as property, not int32

Environment Summary

azure-cli 2.63.0 *

core 2.63.0 * telemetry 1.1.0

Dependencies: msal 1.30.0 azure-mgmt-resource 23.1.1

Additional context

No response

azure-client-tools-bot-prd[bot] commented 4 days ago

Hi @JackBruceShell,

2.63.0 is not the latest Azure CLI(2.66.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

yonzhan commented 3 days ago

storage

calvinhzy commented 3 days ago

Hi @JackBruceShell Seems like it is auto resolving the value type, can you try adding quotes around this string?

vishalholla27 commented 2 days ago

Adding quotes would store data with quotes '0123', Cant we just store 0123