Azure / azure-cli

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

az repos ref delete mentions ref not found while finding multiple matches #29671

Open wkoeter opened 3 months ago

wkoeter commented 3 months ago

Describe the bug

When I have 2 branches with smiliar prefix, and I perform az repos ref delete --name {branchName} it will mention ref not found. Failed to find object_id for ref {branchName}. Please provide object_id.

e.g. having 2 branches: heads/auto/branch1 heads/auto/branch12

calling az repos ref delete --myproject --myrepository --name heads/auto/branch1 returns the error mentioned above.

I think underlying issue is that it does a filter and cannot distinguish between both branches because they both contain the name. I think this because after deleting heads/auto/branch12 manually, the call succeeds without any errors.

This is also supported by the debug logging that finds 2 entries "count":2}.

azext_devops.devops_sdk.client: Response content: b'{"value":[{"name":"refs/heads/auto/branch1","objectId":"redacted","creator":{"displayName":"redacted Koeter","url":"https://spsprodweu4.vssps.visualstudio.com/redacted/_apis/Identities/redacted","_links":{"avatar":{"href":"https://dev.azure.com/organization/_apis/GraphProfile/MemberAvatars/aad.redacted"}},"id":"redacted","uniqueName":"Me@org.com","imageUrl":"https://dev.azure.com/organization/_api/_common/identityImage?id=redacted","descriptor":"aad.redacted"},"url":"https://dev.azure.com/organization/redacted/_apis/git/repositories/redacted/refs?filter=heads%2Fauto%2Fbranch1"},{"name":"refs/heads/auto/branch12","objectId":"redacted","creator":{"displayName":"redacted Koeter","url":"https://spsprodweu4.vssps.visualstudio.com/redacted/_apis/Identities/redacted","_links":{"avatar":{"href":"https://dev.azure.com/organization/_apis/GraphProfile/MemberAvatars/aad.redacted"}},"id":"redacted","uniqueName":"Me@org.com","imageUrl":"https://dev.azure.com/organization/_api/_common/identityImage?id=redacted","descriptor":"aad.redacted"},"url":"https://dev.azure.com/organization/redacted/_apis/git/repositories/redacted/refs?filter=heads%2Fauto%2Fbranch12"}],"count":2}'

Related command

az repos ref delete

Errors

ref not found Failed to find object_id for ref heads/auto/branch1. Please provide object_id.

Issue script & Debug output

cli.knack.cli: Command arguments: ['repos', 'ref', 'delete', '--project', 'project', '--repository', 'Frontend', '--name', 'heads/auto/branch1', '--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 0x01D5F7A8>, <function OutputProducer.on_global_arguments at 0x02088898>, <function CLIQuery.on_global_arguments at 0x020AA668>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'repos': ['azext_devops']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: Total (0)                 0.000         0         0
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
cli.azure.cli.core: azure-devops              0.289        60       192  C:\Users\Me\.azure\cliextensions\azure-devops
cli.azure.cli.core: Total (1)                 0.289        60       192
cli.azure.cli.core: Loaded 60 groups, 192 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : repos ref delete
cli.azure.cli.core: Command table: repos ref delete
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x045600C8>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\Me\.azure\commands\2024-08-07.09-36-50.repos_ref_delete.3416.log'.
az_command_data_logger: command args: repos ref delete --project {} --repository {} --name {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x0459D398>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x0459D348>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x0459D438>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x020888E8>, <function CLIQuery.handle_query_parameter at 0x020AA6B8>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x0459D3E8>, <function DevCommandsLoader.post_parse_args at 0x045C3758>]
az_command_data_logger: extension name: azure-devops
az_command_data_logger: extension version: 1.0.1
cli.azext_devops.dev.common.vsts_git_url_info: Remote url: https://organization@dev.azure.com/organization/project/_git/Oss-Scan
azext_devops.devops_sdk._file_cache: Loading cache file: C:\Users\Me\.azure\azuredevops\cache\remotes.json
azext_devops.devops_sdk._file_cache: attempting to read file C:\Users\Me\.azure\azuredevops\cache\remotes.json as utf-8-sig
cli.azext_devops.dev.common.services: Detect: Url discovery took 0:00:00.157374
cli.azext_devops.dev.common._credentials: Getting credential: azdevops-cli:https://dev.azure.com/organization
cli.azext_devops.dev.common._credentials: Getting credential: azdevops-cli: default
cli.azure.cli.core: Current cloud config:
AzureCloud
cli.azext_devops.dev.common.services: trying to get token (temp) for tenant redacted and user Me@org.com
cli.azure.cli.core.auth.persistence: build_persistence: location='C:\\Users\\Me\\.azure\\msal_token_cache.bin', encrypt=True
cli.azure.cli.core.auth.binary_cache: load: C:\Users\Me\.azure\msal_http_cache.bin
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: openid_config = redacted
msal.application: Broker enabled? False
cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: redacted
msal.application: Cache hit an AT
msal.telemetry: Generate or reuse correlation_id: redacted
cli.azext_devops.dev.common.services: instance recieved in validate_token_for_instance https://dev.azure.com/organization
cli.azext_devops.dev.common.services: instance processed in validate_token_for_instance https://dev.azure.com/organization
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
azext_devops.devops_sdk._file_cache: Loading cache file: C:\Users\Me\.azure-devops\python-sdk\cache\resources.json
azext_devops.devops_sdk._file_cache: attempting to read file C:\Users\Me\.azure-devops\python-sdk\cache\resources.json as utf-8-sig
azext_devops.devops_sdk.connection: File cache hit for resources on: https://dev.azure.com/organization
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
azext_devops.devops_sdk._file_cache: Loading cache file: C:\Users\Me\.azure-devops\python-sdk\cache\options.json
azext_devops.devops_sdk._file_cache: attempting to read file C:\Users\Me\.azure-devops\python-sdk\cache\options.json as utf-8-sig
azext_devops.devops_sdk.client: File cache hit for options on: https://dev.azure.com/organization
azext_devops.devops_sdk.client: Route template: _apis/{resource}/{*projectId}
azext_devops.devops_sdk.client: Api version '5.0'
azext_devops.devops_sdk.client: GET https://dev.azure.com/organization/_apis/projects?stateFilter=all&$top=1&$skip=0
azext_devops.devops_sdk.client: Request content: None
msrest.universal_http: Configuring redirects: allow=True, max=30
msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None
msrest.universal_http: Configuring proxies: ''
msrest.universal_http: Evaluate proxies against ENV settings: True
urllib3.connectionpool: Starting new HTTPS connection (1): dev.azure.com:443
urllib3.connectionpool: https://dev.azure.com:443 "GET /organization/_apis/projects?stateFilter=all&$top=1&$skip=0 HTTP/1.1" 200 342
azext_devops.devops_sdk.client: Response content: b'{"count":1,"value":[{"id":"redacted","name":"Predevelopment","url":"https://dev.azure.com/organization/_apis/projects/redacted","state":"wellFormed","revision":195,"visibility":"private","lastUpdateTime":"2024-08-06T12:28:30.2Z"}]}'
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
cli.azext_devops.dev.common.telemetry: Azure devops telemetry disabled.
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
azext_devops.devops_sdk.connection: File cache hit for resources on: https://dev.azure.com/organization
msrest.universal_http.requests: Configuring retry: max_retries=3, backoff_factor=0.8, max_backoff=90
azext_devops.devops_sdk.client: Route template: {project}/_apis/{area}/repositories/{repositoryId}/{resource}/{*filter}
azext_devops.devops_sdk.client: Api version '5.0'
azext_devops.devops_sdk.client: GET https://dev.azure.com/organization/project/_apis/git/repositories/Frontend/refs?filter=heads%2Fauto%2Fbranch1
azext_devops.devops_sdk.client: Request content: None
msrest.universal_http: Configuring redirects: allow=True, max=30
msrest.universal_http: Configuring request: timeout=100, verify=True, cert=None
msrest.universal_http: Configuring proxies: ''
msrest.universal_http: Evaluate proxies against ENV settings: True
urllib3.connectionpool: Starting new HTTPS connection (1): dev.azure.com:443
urllib3.connectionpool: https://dev.azure.com:443 "GET /organization/project/_apis/git/repositories/Frontend/refs?filter=heads%2Fauto%2Fbranch1 HTTP/1.1" 200 None
azext_devops.devops_sdk.client: Response content: b'{"value":[{"name":"refs/heads/auto/branch1","objectId":"redacted","creator":{"displayName":"redacted Koeter","url":"https://spsprodweu4.vssps.visualstudio.com/redacted/_apis/Identities/redacted","_links":{"avatar":{"href":"https://dev.azure.com/organization/_apis/GraphProfile/MemberAvatars/aad.redacted"}},"id":"redacted","uniqueName":"Me@org.com","imageUrl":"https://dev.azure.com/organization/_api/_common/identityImage?id=redacted","descriptor":"aad.redacted"},"url":"https://dev.azure.com/organization/redacted/_apis/git/repositories/redacted/refs?filter=heads%2Fauto%2Fbranch1"},{"name":"refs/heads/auto/branch12","objectId":"redacted","creator":{"displayName":"redacted Koeter","url":"https://spsprodweu4.vssps.visualstudio.com/redacted/_apis/Identities/redacted","_links":{"avatar":{"href":"https://dev.azure.com/organization/_apis/GraphProfile/MemberAvatars/aad.redacted"}},"id":"redacted","uniqueName":"Me@org.com","imageUrl":"https://dev.azure.com/organization/_api/_common/identityImage?id=redacted","descriptor":"aad.redacted"},"url":"https://dev.azure.com/organization/redacted/_apis/git/repositories/redacted/refs?filter=heads%2Fauto%2Fbranch12"}],"count":2}'
cli.azext_devops.dev.repos.ref: ref not found
cli.azext_devops.dev.common.exception_handler: handling generic error
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 718, in _run_job
  File "C:\Users\Me\.azure\cliextensions\azure-devops\azext_devops\dev\common\exception_handler.py", line 31, in azure_devops_exception_handler
    reraise(*sys.exc_info())
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\six.py", line 719, in reraise
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Users\Me\.azure\cliextensions\azure-devops\azext_devops\dev\repos\ref.py", line 82, in delete_ref
    raise CLIError("Failed to find object_id for ref " + name + ". Please provide object_id.")
knack.util.CLIError: Failed to find object_id for ref heads/auto/branch1. Please provide object_id.

cli.azure.cli.core.azclierror: Failed to find object_id for ref heads/auto/branch1. Please provide object_id.
az_command_data_logger: Failed to find object_id for ref heads/auto/branch1. Please provide object_id.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x04560208>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 3.273 seconds (init: 0.509, invoke: 2.764)

Expected behavior

Branch deleted, or error mentioning it cannot distinguish between multiple branches.

Environment Summary

azure-cli 2.56.0 *

core 2.56.0 * telemetry 1.1.0

Extensions: account 0.2.5 azure-devops 1.0.1 interactive 0.5.1

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

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users__.azure\cliextensions'

Python (Windows) 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:21:31) [MSC v.1936 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

You have 2 update(s) available. Consider updating your CLI installation with 'az upgrade'

Additional context

No response

azure-client-tools-bot-prd[bot] commented 3 months ago

Hi @wkoeter,

2.56.0 is not the latest Azure CLI(2.63.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 months ago

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

microsoft-github-policy-service[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @v-anvashist, @V-hmusukula.

wkoeter commented 3 months ago

Hi @wkoeter,

2.56.0 is not the latest Azure CLI(2.63.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.

Same result after upgrade