Azure / Azure/azure-powershell

Get-AzMySqlFlexibleServerDatabase doesn't handle AzMySqlFlexibleServer objects in pipeline

Open
#20,438 4 comments 0 reactions 0 assignees View on GitHub
act-codegen-extensibility-squad customer-reported feature-request Generator MySQL - Flexible Tracking
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

I'm starting this as an issue, not sure if it's a bug yet or not. (From a user perspective, I would consider it as one.)

If get a FlexServer and pipe it to get the DBs, I get an error:

```
Get-AzMySqlFlexibleServer -ResourceGroupName MyRG| Get-AzMySqlFlexibleServerDatabase
Get-AzMySqlFlexibleServerDatabase_GetViaIdentity: Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}'
```

That object _should_ have all the info needed (the command only needs a server name and resourcegroup name), if nothing else the ResourceGroup name is in the ID property of the server object.

```
$AServer = Get-AzMySqlFlexibleServer -ResourceGroupName MyRG

Name Location SkuName SkuTier AdministratorLogin Version StorageSizeGb
---- -------- ------- ------- ------------------ ------- -------------
SDB East US Standard_B1ms Burstable SomeLogin 5.7 20
```

But there's no ResourceGroup property.

$AServer.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False ServerAutoGenerated System.Object

Perhaps the [mysql.model](https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.powershell.cmdlets.mysql.models.api20210501?view=az-ps-latest) could be updated to include it?

### Script or Debug output

```PowerShell
> Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFlexibleServerDatabase
DEBUG: 10:20:26 PM - GetAzureRMContextCommand end processing.
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/6672a6e4-ef06-4da5-bc5d-4791767c8bf0/resourceGroups/myRG/providers/Microsoft.DBforMySQL/flexibleServers?api-version=2021-05-01
DEBUG: RequestCreated: /subscriptions/6672a6e4-ef06-4da5-bc5d-4791767c8bf0/resourceGroups/myRG/providers/Microsoft.DBforMySQL/flexibleServers?api-version=2021-05-01
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/6672a6e4-ef06-4da5-bc5d-4791767c8bf0/resourceGroups/myRG/providers/Microsoft.DBforMySQL/flexibleServers?api-version=2021-05-01

Headers:
x-ms-unique-id : 12
x-ms-client-request-id : aa09b4de-e806-4d61-8a30-a0ed1921dbd0
CommandName : Get-AzMySqlFlexibleServer
FullCommandName : Get-AzMySqlFlexibleServer_List
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,PSVersion/v7.2.8,Az.MySql/1.1.0

Body:

DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control : no-cache
Pragma : no-cache
X-Content-Type-Options : nosniff
x-ms-request-id : f09e70de-e98c-4d44-8f6d-b2d861b40656
Server : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11996
x-ms-correlation-request-id : 8da649af-09bf-403c-80eb-37838d215f76
x-ms-routing-request-id : WESTUS2:20221214T062025Z:8da649af-09bf-403c-80eb-37838d215f76
Strict-Transport-Security : max-age=31536000; includeSubDomains
Date : Wed, 14 Dec 2022 06:20:25 GMT

Body:
{
"value": [
{
"sku": {
"name": "Standard_B1ms",
"tier": "Burstable"
},
"systemData": {
"createdAt": "2022-12-12T20:17:58.9422276Z"
},
"properties": {
"administratorLogin": "somename",
"storage": {
"storageSizeGB": 20,
"iops": 360,
"autoGrow": "Enabled",
"storageSku": "Premium_LRS"
},
"version": "5.7",
"state": "Ready",
"fullyQualifiedDomainName": "sdb.mysql.database.azure.com",
"availabilityZone": "2",
"maintenanceWindow": {
"customWindow": "Disabled",
"dayOfWeek": 0,
"startHour": 0,
"startMinute": 0
},
"replicationRole": "None",
"replicaCapacity": 10,
"network": {
"publicNetworkAccess": "Enabled"
},
"backup": {
"backupRetentionDays": 7,
"geoRedundantBackup": "Disabled",
"earliestRestoreDate": "2022-12-12T12:27:58.9422276-08:00"
},
"highAvailability": {
"mode": "Disabled",
"state": "NotEnabled",
"standbyAvailabilityZone": ""
}
},
"location": "East US",
"tags": {},
"id": "/subscriptions/6672a6e4-ef06-4da5-bc5d-4791767c8bf0/resourceGroups/MyRG/providers/Microsoft.DBforMySQL/flexibleServers/psi",
"name": "psi",
"type": "Microsoft.DBforMySQL/flexibleServers"
}
]
}

DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: [CmdletException]: Received Exception with message 'Exception - Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}' : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()'
DEBUG: CmdletException: Exception - Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}' : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
Get-AzMySqlFlexibleServerDatabase_GetViaIdentity: Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}'
DEBUG: CmdletProcessRecordEnd:
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.2.8
PSEdition Core
GitCommitId 7.2.8
OS Microsoft Windows 10.0.19045
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 2.10.4 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 1.1.0 Az.MySql {Get-AzMySqlConfiguration, Get-AzMySqlConnectionString, Get-AzMySqlFirewallRule, Get-AzMySqlF…
```

### Error output

```PowerShell
DEBUG: Got version 0 of Az
DEBUG: Got version 0 of Az.Accounts
DEBUG: 10:23:29 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 10:23:29 PM - using account id 'matthew@pontifex-tech.com'...
DEBUG: 10:23:29 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

HistoryId: 25

Message : Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serve
rName}/databases/{databaseName}'
StackTrace : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault,
IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
Exception : System.Exception
InvocationInfo : {Get-AzMySqlFlexibleServerDatabase_GetViaIdentity}
Line : Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFlexibleServerDatabase
Position : At line:1 char:1
+ Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFle …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 25

HistoryId: 22

Message : Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serve
rName}/databases/{databaseName}'
StackTrace : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault,
IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
Exception : System.Exception
InvocationInfo : {Get-AzMySqlFlexibleServerDatabase_GetViaIdentity}
Line : Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFlexibleServerDatabase
Position : At line:1 char:1
+ Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFle …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 22

HistoryId: 21

Message : Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serve
rName}/databases/{databaseName}'
StackTrace : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault,
IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
Exception : System.Exception
InvocationInfo : {Get-AzMySqlFlexibleServerDatabase_GetViaIdentity}
Line : $AServer = Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get-AzMySqlFlexibleServerDatabase
Position : At line:1 char:1
+ $AServer = Get-AzMySqlFlexibleServer -ResourceGroupName $RGName | Get …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 21

HistoryId: 13

Message : [ResourceNotFound] : The Resource 'Microsoft.DBforMySQL/flexibleServers/$Aserver.name' under resource group 'MyRG' was not found. For more
details please go to https://aka.ms/ARMResourceNotFoundFix
StackTrace :
Exception : System.Exception
InvocationInfo : {Get-AzMySqlFlexibleServerDatabase_List}
Line : Get-AzMySqlFlexibleServerDatabase
Position : At line:1 char:1
+ Get-AzMySqlFlexibleServerDatabase
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 13

HistoryId: 1

Message : Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serve
rName}/databases/{databaseName}'
StackTrace : at Microsoft.Azure.PowerShell.Cmdlets.MySql.MySql.FlexibleServerDatabasesGetViaIdentity(String viaIdentity, Func`3 onOk, Func`3 onDefault,
IEventListener eventListener, ISendAsync sender)
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
at Microsoft.Azure.PowerShell.Cmdlets.MySql.Cmdlets.GetAzMySqlFlexibleServerDatabase_GetViaIdentity.ProcessRecordAsync()
Exception : System.Exception
InvocationInfo : {Get-AzMySqlFlexibleServerDatabase_GetViaIdentity}
Line : Get-AzMySqlFlexibleServer -ResourceGroupName MyRG | Get-AzMySqlFlexibleServerDatabase
Position : At line:1 char:1
+ Get-AzMySqlFlexibleServer -ResourceGroupName MyRG | Get-AzMySqlFlexi …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 1

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

DEBUG: 10:23:29 PM - ResolveError end processing.
```

Contributor guide

Open the contributing guide

Research direction

Start at the Get-AzMySqlFlexibleServer and Get-AzMySqlFlexibleServerDatabase pipeline entry points, then inspect the ServerAutoGenerated model and the GetViaIdentity error shown in the report. The work is done when piping a flexible server into the database command derives the required identity and no longer returns the invalid-URI error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, powershell
Domain
cli, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.