Azure / azure-cli

Azure Command-Line Interface
MIT License
3.92k stars 2.89k forks source link

az apim api create --api-id MyApi // generates a warning saying api_id is not a known attribute #27978

Open StephenWBertrand opened 7 months ago

StephenWBertrand commented 7 months ago

Describe the bug

When creating a new api from the az cli, I get a warning saying the api_id field is not a known attribute. If I omit the api-id from the command line (expecting an id to auto generate) then I get an error the following arguments are required: --api-id

The command does appear to actually create the api despite the warning. However my bash script sees this as an error and fails the step.

Related command

az apim api create --api-id MyApi --display-name 'My API' --path '/myapi' --resource-group MyResourceGroup --service-name MyApim --service-url {service-url}

Errors

api_id is not a known attribute of class <class 'azure.mgmt.apimanagement.models._models_py3.ApiContract'> and will be ignored

Issue script & Debug output

az apim api create --service-name MyApim -g MyResourceGroup --api-id MyApi --path '/myapi' --display-name 'My API' --debug cli.knack.cli: Command arguments: ['apim', 'api', 'create', '--service-name', 'MyApim', '-g', 'MyResourceGroup', '--api-id', 'MyApi', '--path', '/myapi', '--display-name', 'My API', '--debug'] cli.knack.cli: init debug log: Enable color in terminal. cli.knack.cli: Event: Cli.PreExecute [] cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f71536b61f0>, <function OutputProducer.on_global_arguments at 0x7f71535d0d30>, <function CLIQuery.on_global_arguments at 0x7f7153568310>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'apim': ['azure.cli.command_modules.apim'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: apim 0.006 14 68 cli.azure.cli.core: Total (1) 0.006 14 68 cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_next'] cli.azure.cli.core: Loading extensions: cli.azure.cli.core: Name Load Time Groups Commands Directory cli.azure.cli.core: ai-examples 0.133 1 1 /usr/lib/python3.9/site-packages/azure-cli-extensions/ai-examples cli.azure.cli.core: Total (1) 0.133 1 1
cli.azure.cli.core: Loaded 15 groups, 69 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : apim api create cli.azure.cli.core: Command table: apim api create cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f7152a0c3a0>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/stephen/.azure/commands/2023-12-06.20-48-27.apim_api_create.963.log'. az_command_data_logger: command args: apim api create --service-name {} -g {} --api-id {} --path {} --display-name {} --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7f71529b0f70>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7f71529e6040>, <function register_cache_arguments..add_cache_arguments at 0x7f71529ede50>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f71535d0dc0>, <function CLIQuery.handle_query_parameter at 0x7f71535683a0>, <function register_ids_argument..parse_ids_arguments at 0x7f71529eddc0>] cli.azure.cli.core.commands.client_factory: Getting management service client client_type=ApiManagementClient urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342 urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 3526 msrestazure.azure_active_directory: MSI: Retrieving a token from http://localhost:50342/oauth2/token, with payload {'resource': 'https://management.core.windows.net/'} azure.mgmt.apimanagement._serialization: api_id is not a known attribute of class <class 'azure.mgmt.apimanagement.models._models_py3.ApiContract'> and will be ignored cli.azure.cli.core.auth.adal_authentication: MSIAuthenticationWrapper.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={} urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342 urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 3526 msrestazure.azure_active_directory: MSI: Retrieving a token from http://localhost:50342/oauth2/token, with payload {'resource': 'https://management.core.windows.net/'} cli.azure.cli.core.auth.adal_authentication: Normalize expires_on: '1701899359' -> 1701899359 cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/*****/resourceGroups/MyResourceGroup/providers/Microsoft.ApiManagement/service/MyApim/apis/MyApi?api-version=2022-08-01' cli.azure.cli.core.sdk.policies: Request method: 'PUT' cli.azure.cli.core.sdk.policies: Request headers: cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json' cli.azure.cli.core.sdk.policies: 'Content-Length': '130' cli.azure.cli.core.sdk.policies: 'Accept': 'application/json' cli.azure.cli.core.sdk.policies: 'x-ms-client-request-id': 'ce2019b4-9478-11ee-97e1-00155dccccba' cli.azure.cli.core.sdk.policies: 'CommandName': 'apim api create' cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--service-name -g --api-id --path --display-name --debug' cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.55.0 (RPM) azsdk-python-mgmt-apimanagement/4.0.0 Python/3.9.14 (Linux-5.10.102.2-microsoft-standard-x86_64-with-glibc2.35) cloud-shell/1.0' cli.azure.cli.core.sdk.policies: 'Authorization': '*' cli.azure.cli.core.sdk.policies: Request body: cli.azure.cli.core.sdk.policies: {"properties": {"type": "http", "subscriptionRequired": false, "displayName": "My API", "path": "/myapi", "protocols": ["https"]}} urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443 urllib3.connectionpool: https://management.azure.com:443 "PUT /subscriptions/****/resourceGroups/MyResourceGroup/providers/Microsoft.ApiManagement/service/MyApim/apis/MyApi?api-version=2022-08-01 HTTP/1.1" 404 107 cli.azure.cli.core.sdk.policies: Response status: 404 cli.azure.cli.core.sdk.policies: Response headers: cli.azure.cli.core.sdk.policies: 'Cache-Control': 'no-cache' cli.azure.cli.core.sdk.policies: 'Pragma': 'no-cache' cli.azure.cli.core.sdk.policies: 'Content-Length': '107' cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json; charset=utf-8' cli.azure.cli.core.sdk.policies: 'Expires': '-1' cli.azure.cli.core.sdk.policies: 'x-ms-failure-cause': 'gateway' cli.azure.cli.core.sdk.policies: 'x-ms-request-id': 'ff9a62f6-520d-4cd6-a18d-da2fb2598201' cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': 'ff9a62f6-520d-4cd6-a18d-da2fb2598201' cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'NORTHCENTRALUS:20231206T204828Z:ff9a62f6-520d-4cd6-a18d-da2fb2598201' cli.azure.cli.core.sdk.policies: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains' cli.azure.cli.core.sdk.policies: 'X-Content-Type-Options': 'nosniff' cli.azure.cli.core.sdk.policies: 'X-Cache': 'CONFIG_NOCACHE' cli.azure.cli.core.sdk.policies: 'X-MSEdge-Ref': 'Ref A: 7C3B8AD16CBB4D8B8B522756BE001E0B Ref B: MNZ221060610049 Ref C: 2023-12-06T20:48:27Z' cli.azure.cli.core.sdk.policies: 'Date': 'Wed, 06 Dec 2023 20:48:27 GMT' cli.azure.cli.core.sdk.policies: Response content: cli.azure.cli.core.sdk.policies: {"error":{"code":"ResourceGroupNotFound","message":"Resource group 'MyResourceGroup' could not be found."}} cli.azure.cli.core.azclierror: Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 333, in call return self.handler(*args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(command_args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/command_modules/apim/custom.py", line 337, in apim_api_create return sdk_no_wait(no_wait, client.api.begin_create_or_update, File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/util.py", line 710, in sdk_no_wait return func(*args, *kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer return func(args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt/apimanagement/operations/_api_operations.py", line 890, in begin_create_or_update raw_result = self._create_or_update_initial( File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt/apimanagement/operations/_api_operations.py", line 725, in _create_or_update_initial map_error(status_code=response.status_code, response=response, error_map=error_map) File "/usr/lib64/az/lib/python3.9/site-packages/azure/core/exceptions.py", line 107, in map_error raise error azure.core.exceptions.ResourceNotFoundError: (ResourceGroupNotFound) Resource group 'MyResourceGroup' could not be found. Code: ResourceGroupNotFound Message: Resource group 'MyResourceGroup' could not be found.

cli.azure.cli.core.azclierror: (ResourceGroupNotFound) Resource group 'MyResourceGroup' could not be found. Code: ResourceGroupNotFound Message: Resource group 'MyResourceGroup' could not be found. az_command_data_logger: (ResourceGroupNotFound) Resource group 'MyResourceGroup' could not be found. Code: ResourceGroupNotFound Message: Resource group 'MyResourceGroup' could not be found. cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f7152a0c5e0>] az_command_data_logger: exit code: 3 cli.main: Command ran in 1.391 seconds (init: 0.142, invoke: 1.249) telemetry.main: Begin splitting cli events and extra events, total events: 1 telemetry.client: Accumulated 0 events. Flush the clients. telemetry.main: Finish splitting cli events and extra events, cli events: 1 telemetry.save: Save telemetry record of length 3679 in cache telemetry.main: Begin creating telemetry upload process. telemetry.process: Creating upload process: "/usr/bin/python3.9 /usr/lib/az/lib/python3.9/site-packages/azure/cli/telemetry/init.py /home/stephen/.azure" telemetry.process: Return from creating process telemetry.main: Finish creating telemetry upload process.

Expected behavior

Given api-id is a legitimate field to be passed in (and in fact required), then I would expect no warning message.

Environment Summary

az --version azure-cli 2.55.0

core 2.55.0 telemetry 1.1.0

Extensions: ai-examples 0.2.5 ml 2.22.0 ssh 2.0.2

Dependencies: msal 1.24.0b2 azure-mgmt-resource 23.1.0b2

Additional context

No response

yonzhan commented 7 months ago

Thank you for opening this issue, we will look into it.

akanshajain1 commented 5 months ago

Hi! Could you please update, is this issue still persists or are you able to resolve it?

jepperaskdk commented 1 week ago

I'm getting this as well. I assume it is just a mistake to flag that as a warning by az-cli?