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

refactor: align backend response status with UI #4433

Merged
merged 9 commits into from
Dec 22, 2023
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ These are the section headers that we use:
- Added `POST /api/v1/me/responses/bulk` endpoint to create responses in bulk for current user. ([#4380](https://github.com/argilla-io/argilla/pull/4380))
- Added new CLI task to reindex datasets and records into the search engine. ([#4404](https://github.com/argilla-io/argilla/pull/4404))

### Fixed
###Fixed
frascuchon marked this conversation as resolved.
Show resolved Hide resolved

- Fixed total records on pagination component ([#4424](https://github.com/argilla-io/argilla/pull/4424))

### Deprecated

- The `missing` response status for filtering records is deprecated and will be removed in the release 1.23.0. Use `pending` instead. ([#4433](https://github.com/argilla-io/argilla/pull/4433))
frascuchon marked this conversation as resolved.
Show resolved Hide resolved

## [1.20.0](https://github.com/argilla-io/argilla/compare/v1.19.0...v1.20.0)

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/argilla/server/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ResponseStatus(str, Enum):

class ResponseStatusFilter(str, Enum):
draft = "draft"
missing = "missing"
missing = "missing" # Deprecated, use pending instead
pending = "pending"
submitted = "submitted"
discarded = "discarded"

Expand Down
13 changes: 13 additions & 0 deletions src/argilla/server/search_engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from argilla.server.enums import (
MetadataPropertyType,
RecordSortField,
ResponseStatus,
ResponseStatusFilter,
SimilarityOrder,
SortOrder,
Expand Down Expand Up @@ -134,6 +135,18 @@ class UserResponseStatusFilter(BaseModel):
class Config:
arbitrary_types_allowed = True

@property
def response_statuses(self) -> List[ResponseStatus]:
return [
status.value
for status in self.statuses
if status not in [ResponseStatusFilter.pending, ResponseStatusFilter.missing]
]

@property
def has_pending_status(self) -> bool:
return ResponseStatusFilter.pending in self.statuses or ResponseStatusFilter.missing in self.statuses


class MetadataFilter(BaseModel):
metadata_property: MetadataProperty
Expand Down
9 changes: 3 additions & 6 deletions src/argilla/server/search_engine/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,13 @@ def _build_response_status_filter(status_filter: UserResponseStatusFilter) -> Di
response_field = f"responses.{status_filter.user.username}.status"

filters = []
statuses = [
ResponseStatus(status).value for status in status_filter.statuses if status != ResponseStatusFilter.missing
]
if ResponseStatusFilter.missing in status_filter.statuses:
if status_filter.has_pending_status:
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
filters.append({"bool": {"must_not": {"exists": {"field": response_field}}}})

if statuses:
if status_filter.response_statuses:
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
filters.append(es_terms_query(response_field, values=statuses))
filters.append(es_terms_query(response_field, values=status_filter.response_statuses))

return {"bool": {"should": filters, "minimum_should_match": 1}}

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/server/api/v1/test_list_dataset_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ async def test_list_dataset_records_with_metadata_filter(

@pytest.mark.skip(reason="Factory integration with search engine")
@pytest.mark.parametrize(
"response_status_filter", ["missing", "discarded", "submitted", "draft", ["submitted", "draft"]]
"response_status_filter", ["missing", "pending", "discarded", "submitted", "draft", ["submitted", "draft"]]
)
async def test_list_dataset_records_with_response_status_filter(
self,
Expand Down Expand Up @@ -1235,7 +1235,7 @@ async def test_list_current_user_dataset_records_with_metadata_filter(
)

@pytest.mark.skip(reason="Factory integration with search engine")
@pytest.mark.parametrize("response_status_filter", ["missing", "discarded", "submitted", "draft"])
@pytest.mark.parametrize("response_status_filter", ["missing", "pending", "discarded", "submitted", "draft"])
async def test_list_current_user_dataset_records_with_response_status_filter(
self, async_client: "AsyncClient", owner: "User", owner_auth_header: dict, response_status_filter: str
):
Expand Down Expand Up @@ -1269,7 +1269,7 @@ async def test_list_current_user_dataset_records_with_response_status_filter(

assert len(response_json["items"]) == num_responses_per_status

if response_status_filter == "missing":
if response_status_filter in ["missing", "pending"]:
assert all([len(record["responses"]) == 0 for record in response_json["items"]])
else:
assert all(
Expand Down
Loading