diff --git a/argilla-server/src/argilla_server/apis/v1/handlers/metadata_properties.py b/argilla-server/src/argilla_server/apis/v1/handlers/metadata_properties.py index bedf7b6091..b6c3553d38 100644 --- a/argilla-server/src/argilla_server/apis/v1/handlers/metadata_properties.py +++ b/argilla-server/src/argilla_server/apis/v1/handlers/metadata_properties.py @@ -14,7 +14,7 @@ from uuid import UUID -from fastapi import APIRouter, Depends, HTTPException, Security, status +from fastapi import APIRouter, Depends, Security, status from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import selectinload @@ -88,11 +88,4 @@ async def delete_metadata_property( await authorize(current_user, MetadataPropertyPolicyV1.delete(metadata_property)) - # TODO: We should split API v1 into different FastAPI apps so we can customize error management. - # After mapping ValueError to 422 errors for API v1 then we can remove this try except. - try: - await datasets.delete_metadata_property(db, metadata_property) - except ValueError as err: - raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=str(err)) - - return metadata_property + return await datasets.delete_metadata_property(db, metadata_property) diff --git a/argilla-server/tests/unit/api/v1/test_metadata_properties.py b/argilla-server/tests/unit/api/v1/test_metadata_properties.py index 8ab0dad868..3783690288 100644 --- a/argilla-server/tests/unit/api/v1/test_metadata_properties.py +++ b/argilla-server/tests/unit/api/v1/test_metadata_properties.py @@ -396,14 +396,12 @@ async def test_delete_metadata_property(async_client: "AsyncClient", db: "AsyncS user = await UserFactory.create(role=user_role, workspaces=[metadata_property.dataset.workspace]) response = await async_client.delete( - f"/api/v1/metadata-properties/{metadata_property.id}", headers={API_KEY_HEADER_NAME: user.api_key} + f"/api/v1/metadata-properties/{metadata_property.id}", + headers={API_KEY_HEADER_NAME: user.api_key}, ) assert response.status_code == 200 - assert (await db.execute(select(func.count(MetadataProperty.id)))).scalar() == 0 - - response_body = response.json() - assert response_body == { + assert response.json() == { "id": str(metadata_property.id), "name": "name", "title": "title", @@ -414,6 +412,8 @@ async def test_delete_metadata_property(async_client: "AsyncClient", db: "AsyncS "updated_at": metadata_property.updated_at.isoformat(), } + assert (await db.execute(select(func.count(MetadataProperty.id)))).scalar() == 0 + @pytest.mark.asyncio async def test_delete_metadata_property_without_authentication(async_client: "AsyncClient", db: "AsyncSession"): @@ -433,7 +433,8 @@ async def test_delete_metadata_property_as_admin_from_different_workspace( metadata_property = await IntegerMetadataPropertyFactory.create() response = await async_client.delete( - f"/api/v1/metadata-properties/{metadata_property.id}", headers={API_KEY_HEADER_NAME: admin.api_key} + f"/api/v1/metadata-properties/{metadata_property.id}", + headers={API_KEY_HEADER_NAME: admin.api_key}, ) assert response.status_code == 403 @@ -446,7 +447,8 @@ async def test_delete_metadata_property_as_annotator(async_client: "AsyncClient" metadata_property = await IntegerMetadataPropertyFactory.create() response = await async_client.delete( - f"/api/v1/metadata-properties/{metadata_property.id}", headers={API_KEY_HEADER_NAME: annotator.api_key} + f"/api/v1/metadata-properties/{metadata_property.id}", + headers={API_KEY_HEADER_NAME: annotator.api_key}, ) assert response.status_code == 403