Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty repository in container registry causes unexpected SDK issue when trying to list tags #28234

Closed
l3ender opened this issue Jan 9, 2023 · 15 comments · Fixed by #29445
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Container Registry customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@l3ender
Copy link

l3ender commented Jan 9, 2023

  • Package Name: azure-containerregistry
  • Package Version: 1.0.0
  • Operating System: macOS 13.1
  • Python Version: 3.9.6

Describe the bug
When trying to list the tags on an empty container registry repository (all tags have been removed), the SDK produces the unexpected error TypeError: 'NoneType' object is not iterable. The error is thrown when trying to iterate on a non-none object of type azure.core.paging.ItemPaged, which is what is unexpected.

To Reproduce
Steps to reproduce the behavior:

  1. Delete all tags for a container registry's repository.

  2. Try and use the SDK to list tags for the empty repository. The issue will come when try to iterate on the response (even if a check for None is done prior):

    client = ContainerRegistryClient(endpoint=registry_endpoint, credential=credentials, audience="https://management.azure.com")
    response = client.list_tag_properties(repository=repository_name)
    if response is not None:
        for tag in response: # <--- error occurs here - TypeError: 'NoneType' object is not iterable
                print("\t" + tag.name)

I have created a script which reproduces the issue, which also includes setup of a registry/repository for testing. See below for more detail.

Expected behavior
The SDK should either not throw an issue when trying to iterate on the tag response (ItemPaged type) OR return a NoneType response so that appropriate checks can be added by client applications.

Screenshots

Below is a screenshot in Azure portal of a repository which has had all tags removed:

image

Using the SDK to list tags for "my-test-repository" causes the above issue to occur.

Additional context

I've created a script which completely initializes a container registry and and puts it in the desired state, and then reproduces the error.

  1. Install required dependencies:

    azure-containerregistry==1.0.0
    azure-identity==1.12.0
    azure-mgmt-containerregistry==10.0.0
    
  2. Create environment variables for test script, and populate with environment-specific values.

    export AZURE_SUBSCRIPTION_ID=xxx
    export AZURE_CLIENT_ID=xxx
    export AZURE_CLIENT_SECRET=xxx
    export AZURE_TENANT_ID=xxx
    export AZURE_RESOURCE_GROUP=xxx
    export AZURE_REGISTRY_NAME=xxx
    
  3. Run the following script to recreate the issue. The script will autocreate the container registry (and repository) if it doesn't exist. The script will then try and list tags for the empty repository.

    #!/usr/bin/python
    
    import os
    from azure.identity._credentials import client_secret
    from azure.containerregistry import ContainerRegistryClient
    from azure.mgmt.containerregistry import ContainerRegistryManagementClient
    from azure.core.exceptions import ResourceNotFoundError
    from azure.mgmt.containerregistry.models import (RegistryNameCheckRequest, Registry, Sku, ImportImageParameters, ImportSource)
    
    
    subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'xxx')
    credentials = client_secret.ClientSecretCredential(
        client_id=os.environ.get('AZURE_CLIENT_ID', 'xxx'),
        client_secret=os.environ.get('AZURE_CLIENT_SECRET', 'xxx'),
        tenant_id=os.environ.get('AZURE_TENANT_ID', 'xxx'),
    )
    
    registry_name = os.environ.get('AZURE_REGISTRY_NAME', 'xxx')
    registry_endpoint = registry_name + ".azurecr.io"
    repository_name = "my-test-repository"
    
    def list_tags():
        print(f"listing tags for repository {repository_name} in registry {registry_name}")
        client = ContainerRegistryClient(endpoint=registry_endpoint, credential=credentials, audience="https://management.azure.com")
        response = client.list_tag_properties(repository=repository_name)
        if response is not None:
            for tag in response:
                    print("\t" + tag.name)
        else:
            print('response is none')
    
    
    def initialize_registry():
        resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'xxx')
        mgmt_client = ContainerRegistryManagementClient(credential=credentials, subscription_id=subscription_id)
        print(f"checking for registry '{registry_name}' in resource group '{resource_group}'")
        try:
            registry = mgmt_client.registries.get(resource_group_name=resource_group, registry_name=registry_name)
        except ResourceNotFoundError:
            registry = None
    
        if registry is None:
            print(f"registry '{registry_name}' does not exist; checking for name availability")
            status = mgmt_client.registries.check_name_availability(registry_name_check_request=RegistryNameCheckRequest(name=registry_name))
            if status.name_available:
                print(f"creating registry '{registry_name}'")
                poller = mgmt_client.registries.begin_create(resource_group_name=resource_group, registry_name=registry_name, registry=
                    Registry(location="eastus", sku=Sku(name="Basic"))
                )
                while not poller.done():
                    poller.wait(timeout=5)
                registry = poller.result()
                print(f"registry '{registry_name}' created!")
            else:
                print(f"name '{registry_name}' is unavailable, please use a different one!")
                exit(1)
    
        print(f"registry '{registry_name}' exists, checking for repository '{repository_name}'")
        client = ContainerRegistryClient(endpoint=registry_endpoint, credential=credentials, audience="https://management.azure.com")
        try:
            repository = client.get_repository_properties(repository=repository_name)
        except ResourceNotFoundError:
            repository = None
        
        test_image = "hello-world:latest"
        if repository is None:
            print(f"creating repository '{repository_name}' by importing test image '{test_image}'")
            params = ImportImageParameters(
                target_tags=[repository_name + ":latest"],
                source=ImportSource(
                    registry_uri="docker.io",
                    source_image="library/" + test_image,
                )
            )
            poller = mgmt_client.registries.begin_import_image(resource_group_name=resource_group, registry_name=registry_name, parameters=params)
            while not poller.done():
                poller.wait(timeout=5)
            print(f"test image {test_image} successfully imported to '{repository_name}'")
    
        print(f"ensuring test image '{test_image}' is removed from repository '{repository_name}'")
        client.delete_tag(repository=repository_name, tag="latest")
    
        print(f"repository '{repository_name}' is empty and ready for recreating the issue!\n")
    
    
    initialize_registry()
    list_tags()
@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 9, 2023
@github-actions github-actions bot added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jan 9, 2023
@xiangyan99 xiangyan99 added Container Registry and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jan 11, 2023
@ghost ghost added the needs-team-attention This issue needs attention from Azure service team or SDK team label Jan 11, 2023
@xiangyan99
Copy link
Member

Thanks for the feedback, we’ll investigate asap.

@xiangyan99 xiangyan99 added the Client This issue points to a problem in the data-plane of the library. label Jan 11, 2023
@l3ender
Copy link
Author

l3ender commented Feb 2, 2023

Hello @xiangyan99 and @YalinLi0312, any update on this issue? Thanks!

@l3ender
Copy link
Author

l3ender commented Feb 14, 2023

Hello @xiangyan99 and @YalinLi0312, any findings on the issue? Thank you!

@YalinLi0312
Copy link
Member

Hi @l3ender , we are preparing new features in this sdk and will back to investigate this issue asap. Thanks for your patience!

@l3ender
Copy link
Author

l3ender commented Feb 27, 2023

Hi @YalinLi0312, any update? Thanks!

@YalinLi0312
Copy link
Member

@l3ender We haven't got a chance to investigate this issue yet, but I can tag you once we have updates. Sorry for any inconvenience.

@l3ender
Copy link
Author

l3ender commented Mar 1, 2023

@YalinLi0312, thank you for the response. Is there anyone else who can support this issue since you are busy? It has already been 8 weeks with no update!

Thank you!

@l3ender
Copy link
Author

l3ender commented Mar 17, 2023

Hello @xiangyan99 and @YalinLi0312, any update? This issue is blocking our ability to use the SDK for container registry management!

@YalinLi0312
Copy link
Member

Hi @l3ender , we are working on it. You can expect it get fix in our next preview release.

@YalinLi0312 YalinLi0312 reopened this Mar 20, 2023
@YalinLi0312 YalinLi0312 added the issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. label Mar 20, 2023
@ghost
Copy link

ghost commented Mar 20, 2023

Hi @l3ender. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

@ghost ghost removed the needs-team-attention This issue needs attention from Azure service team or SDK team label Mar 20, 2023
@YalinLi0312
Copy link
Member

@l3ender Here's the release with the bug fix: Here's the release: https://pypi.org/project/azure-containerregistry/1.1.0b2/ Please give it a try, it should unblock your work.

@ghost
Copy link

ghost commented Apr 1, 2023

Hi @l3ender, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.

@ghost ghost closed this as completed Apr 1, 2023
@l3ender
Copy link
Author

l3ender commented Apr 7, 2023

Sorry I didn't respond sooner, but I have tested the beta version and can confirm it is working! Thank you!!

When will a stable release occur with the same?

/unresolve

@ghost ghost reopened this Apr 7, 2023
@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. labels Apr 7, 2023
@YalinLi0312
Copy link
Member

  • Thanks for your confirm, I'll close this issue then. (Also feel free to reopen if you think it's not done.)
  • We are preparing a GA which will be available in late April or early May.

@l3ender
Copy link
Author

l3ender commented May 12, 2023

Any update on a GA release? Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Container Registry customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants