Skip to content

Unable to delete volume comment #1727

Open

Description

@sassai

Describe the bug

Unable to delete a comment of a volume after initially assigning a comment

To Reproduce

import string
from random import choice
from typing import Any, AsyncGenerator, Generator

import pytest
from testcontainers.core.container import DockerContainer
from testcontainers.core.wait_strategies import HttpWaitStrategy
from unitycatalog.client import (
    ApiClient,
    CatalogsApi,
    Configuration,
    CreateCatalog,
    CreateSchema,
    CreateVolumeRequestContent,
    SchemasApi,
    UpdateVolumeRequestContent,
    VolumeInfo,
    VolumesApi,
    VolumeType,
)


@pytest.fixture
def docker_container() -> Generator[DockerContainer, Any, None]:
    unity_catalog: DockerContainer = (
        DockerContainer(image="unitycatalog/unitycatalog:v0.5.0")
        .with_bind_ports(container=8080, host=8080)
        .with_env(key="storage-root.tables", value="/tmp/uc/tables")
        .waiting_for(
            strategy=HttpWaitStrategy(
                port=8080, path="/api/2.1/unity-catalog/catalogs"
            ).for_status_code(code=200)
        )
    )
    unity_catalog.start()
    yield unity_catalog
    unity_catalog.stop()


@pytest.fixture
async def api_client(
    docker_container: DockerContainer,
) -> AsyncGenerator[ApiClient, Any]:
    config = Configuration()
    config.host = (
        f"http://{docker_container.get_container_host_ip()}:8080"
        "/api/2.1/unity-catalog"
    )
    api_client = ApiClient(configuration=config)
    yield api_client
    await api_client.close()


@pytest.fixture
async def catalog_name(api_client: ApiClient) -> AsyncGenerator[str, Any]:
    catalog_name: str = "".join(
        choice(seq=string.ascii_lowercase) for _ in range(10)
    )
    catalog_api = CatalogsApi(api_client=api_client)
    create_catalog = CreateCatalog(
        name=catalog_name, storage_root="/tmp/uc/catalogs"
    )
    await catalog_api.create_catalog(create_catalog=create_catalog)
    yield catalog_name


@pytest.fixture
async def database(
    api_client: ApiClient, catalog_name: str
) -> AsyncGenerator[str, Any]:
    database_name: str = "".join(
        choice(seq=string.ascii_lowercase) for _ in range(10)
    )
    schemas_api = SchemasApi(api_client=api_client)

    schema = CreateSchema(
        name=database_name, catalog_name=catalog_name, comment=None
    )
    await schemas_api.create_schema(create_schema=schema)
    yield database_name


@pytest.fixture
async def volume(
    api_client: ApiClient,
    catalog_name: str,
    database: str,
) -> AsyncGenerator[str, Any]:
    volumes_api = VolumesApi(api_client=api_client)
    volume_name: str = "".join(
        choice(seq=string.ascii_lowercase) for _ in range(10)
    )
    create_volume_request_content = CreateVolumeRequestContent(
        catalog_name=catalog_name,
        schema_name=database,
        name=volume_name,
        volume_type=VolumeType.MANAGED,
        comment="This is a volume comment",
    )
    await volumes_api.create_volume(
        create_volume_request_content=create_volume_request_content
    )
    yield volume_name


async def test_set_volume_comment_empty_string(
    api_client: ApiClient, catalog_name: str, database: str, volume: str
):
    update_volume_request_content = UpdateVolumeRequestContent(comment=None)
    volumes_api = VolumesApi(api_client=api_client)
    volume_info: VolumeInfo = await volumes_api.update_volume(
        name=f"{catalog_name}.{database}.{volume}",
        update_volume_request_content=update_volume_request_content,
    )
    assert not volume_info.comment

Setting the volume comment to an empty string results in the following error

E       pydantic_core._pydantic_core.ValidationError: 1 validation error for UpdateVolumeRequestContent
E       comment
E         String should have at least 1 character [type=string_too_short, input_value='', input_type=str]
E           For further information visit https://errors.pydantic.dev/2.12/v/string_too_short

Expected behavior

Volume comment is deleted when setting it to none.

System [please complete the following information]:

  • OS: macOS 26.6
  • Unity Catalog: 0.5.0

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions