Skip to content

Commit

Permalink
feat: change dataset publish validation from at least one field to ha…
Browse files Browse the repository at this point in the history
…ve at least one field
  • Loading branch information
jfcalvo committed Oct 4, 2024
1 parent 6c5d5e9 commit 3b49f6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions argilla-server/src/argilla_server/validators/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions argilla-server/tests/unit/api/handlers/v1/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3b49f6d

Please sign in to comment.