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

feat: change dataset publish validation from at least one required field to at least one field (required or not) #5569

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading