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

fix: Accept draft responses on dataset records creation #4354

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ These are the section headers that we use:
- Fixed error in the unification strategy for `RankingQuestion` ([#4295](https://github.com/argilla-io/argilla/pull/4295))
- Fixed `TextClassificationSettings.labels_schema` order was not being preserved. Closes [#3828](https://github.com/argilla-io/argilla/issues/3828) ([#4332](https://github.com/argilla-io/argilla/pull/4332))
- Fixed error when requesting non-existing API endpoints. Closes [#4073](https://github.com/argilla-io/argilla/issues/4073) ([#4325](https://github.com/argilla-io/argilla/pull/4325))
- Fixed error when passing `draft` responses to create records endpoint. ([#4354](https://github.com/argilla-io/argilla/pull/4354))

### Changed

Expand Down
8 changes: 7 additions & 1 deletion src/argilla/server/schemas/v1/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,14 @@ class UserDiscardedResponseCreate(BaseModel):
status: Literal[ResponseStatus.discarded]


class UserDraftResponseCreate(BaseModel):
user_id: UUID
values: Dict[str, ResponseValueCreate]
status: Literal[ResponseStatus.draft]


UserResponseCreate = Annotated[
Union[UserSubmittedResponseCreate, UserDiscardedResponseCreate],
Union[UserSubmittedResponseCreate, UserDraftResponseCreate, UserDiscardedResponseCreate],
PydanticField(discriminator="status"),
]

Expand Down
39 changes: 39 additions & 0 deletions tests/unit/server/api/v1/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3088,6 +3088,45 @@ async def test_create_dataset_records_with_discarded_response(
await db.execute(select(func.count(Response.id)).filter(Response.status == ResponseStatus.discarded))
).scalar() == 1

async def test_create_dataset_records_with_draft_response(
self,
async_client: "AsyncClient",
db: "AsyncSession",
owner: User,
owner_auth_header: dict,
):
dataset = await DatasetFactory.create(status=DatasetStatus.ready)
await TextFieldFactory.create(name="input", dataset=dataset)
await TextFieldFactory.create(name="output", dataset=dataset)

await TextQuestionFactory.create(name="input_ok", dataset=dataset)
await TextQuestionFactory.create(name="output_ok", dataset=dataset)

records_json = {
"items": [
{
"fields": {"input": "Say Hello", "output": "Hello"},
"responses": [
{
"values": {"input_ok": {"value": "yes"}, "output_ok": {"value": "yes"}},
"status": "draft",
"user_id": str(owner.id),
}
],
},
]
}

response = await async_client.post(
f"/api/v1/datasets/{dataset.id}/records", headers=owner_auth_header, json=records_json
)

assert response.status_code == 204
assert (await db.execute(select(func.count(Record.id)))).scalar() == 1
assert (
await db.execute(select(func.count(Response.id)).filter(Response.status == ResponseStatus.draft))
).scalar() == 1

async def test_create_dataset_records_with_invalid_response_status(
self,
async_client: "AsyncClient",
Expand Down