From 3b49f6de06f6c613c0813d119c562fa704562543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Fri, 4 Oct 2024 16:05:21 +0200 Subject: [PATCH] feat: change dataset publish validation from at least one field to have at least one field --- argilla-server/src/argilla_server/validators/datasets.py | 8 ++++---- .../tests/unit/api/handlers/v1/test_datasets.py | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/argilla-server/src/argilla_server/validators/datasets.py b/argilla-server/src/argilla_server/validators/datasets.py index 9c6daf8085..a7a2f3f979 100644 --- a/argilla-server/src/argilla_server/validators/datasets.py +++ b/argilla-server/src/argilla_server/validators/datasets.py @@ -45,7 +45,7 @@ class DatasetPublishValidator: @classmethod async def validate(cls, db: AsyncSession, dataset: Dataset) -> None: await cls._validate_has_not_been_published_yet(db, dataset) - await cls._validate_has_at_least_one_required_field(db, dataset) + await cls._validate_has_at_least_one_field(db, dataset) await cls._validate_has_at_least_one_required_question(db, dataset) @classmethod @@ -54,9 +54,9 @@ async def _validate_has_not_been_published_yet(cls, db: AsyncSession, dataset: D raise UnprocessableEntityError("Dataset has already been published") @classmethod - async def _validate_has_at_least_one_required_field(cls, db: AsyncSession, dataset: Dataset) -> None: - if await Field.count_by(db, dataset_id=dataset.id, required=True) == 0: - raise UnprocessableEntityError("Dataset cannot be published without required fields") + async def _validate_has_at_least_one_field(cls, db: AsyncSession, dataset: Dataset) -> None: + if await Field.count_by(db, dataset_id=dataset.id) == 0: + raise UnprocessableEntityError("Dataset cannot be published without fields") @classmethod async def _validate_has_at_least_one_required_question(cls, db: AsyncSession, dataset: Dataset) -> None: diff --git a/argilla-server/tests/unit/api/handlers/v1/test_datasets.py b/argilla-server/tests/unit/api/handlers/v1/test_datasets.py index 95da034f73..4b57a24888 100644 --- a/argilla-server/tests/unit/api/handlers/v1/test_datasets.py +++ b/argilla-server/tests/unit/api/handlers/v1/test_datasets.py @@ -4675,17 +4675,16 @@ async def test_publish_dataset_already_published( assert response.json() == {"detail": "Dataset has already been published"} assert (await db.execute(select(func.count(Record.id)))).scalar() == 0 - async def test_publish_dataset_without_required_fields( + async def test_publish_dataset_without_fields( self, async_client: "AsyncClient", db: "AsyncSession", owner_auth_header: dict ): dataset = await DatasetFactory.create() - await TextFieldFactory.create(dataset=dataset, required=False) await TextQuestionFactory.create(dataset=dataset, required=True) response = await async_client.put(f"/api/v1/datasets/{dataset.id}/publish", headers=owner_auth_header) assert response.status_code == 422 - assert response.json() == {"detail": "Dataset cannot be published without required fields"} + assert response.json() == {"detail": "Dataset cannot be published without fields"} assert (await db.execute(select(func.count(Record.id)))).scalar() == 0 async def test_publish_dataset_without_required_questions(