Skip to content

Commit 5622e96

Browse files
authored
fix: Prevent compute metrics for draft datasets (#5624)
# Description <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Dataset progress and user metrics are not available for draft datasets. **Type of change** <!-- Please delete options that are not relevant. Remember to title the PR according to the type of change --> - Bug fix (non-breaking change which fixes an issue) **How Has This Been Tested** <!-- Please add some reference about how your feature has been tested. --> **Checklist** <!-- Please go over the list and make sure you've taken everything into account --> - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)
1 parent b9dac8d commit 5622e96

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

argilla-server/src/argilla_server/search_engine/commons.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,19 @@ async def delete_record_suggestion(self, suggestion: Suggestion):
395395
)
396396

397397
async def get_dataset_progress(self, dataset: Dataset) -> dict:
398+
if dataset.is_draft:
399+
return {}
400+
398401
index_name = es_index_name_for_dataset(dataset)
399402

400403
metrics = await self._compute_terms_metrics_for(index_name, "status")
401404

402405
return {"total": metrics.total, **{metric.term: metric.count for metric in metrics.values}}
403406

404407
async def get_dataset_user_progress(self, dataset: Dataset, user: User) -> dict:
408+
if dataset.is_draft:
409+
return {}
410+
405411
index_name = es_index_name_for_dataset(dataset)
406412

407413
result = await self._compute_terms_metrics_for(

argilla-server/tests/unit/search_engine/test_commons.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
SimilarityOrder,
2929
RecordStatus,
3030
SortOrder,
31+
DatasetStatus,
3132
)
3233
from argilla_server.models import Dataset, Question, Record, User, VectorSettings, Vector
3334
from argilla_server.search_engine import (
@@ -120,6 +121,7 @@ async def test_banking_sentiment_dataset_non_indexed():
120121
await FloatMetadataPropertyFactory.create(name="seq_float"),
121122
],
122123
questions=[text_question, rating_question],
124+
status=DatasetStatus.ready,
123125
)
124126

125127
records = [
@@ -1352,6 +1354,13 @@ async def test_get_dataset_user_progress_with_response(
13521354
"submitted": 1,
13531355
}
13541356

1357+
async def test_get_dataset_user_progress_for_draft_dataset(self, search_engine: BaseElasticAndOpenSearchEngine):
1358+
dataset = await DatasetFactory.create(status=DatasetStatus.draft)
1359+
user = await UserFactory.create()
1360+
1361+
progress = await search_engine.get_dataset_user_progress(dataset, user=user)
1362+
assert progress == {}
1363+
13551364
async def test_get_dataset_progress_with_pending_records(
13561365
self,
13571366
search_engine: BaseElasticAndOpenSearchEngine,
@@ -1388,6 +1397,11 @@ async def test_get_dataset_progress_with_completed_records(
13881397
progress = await search_engine.get_dataset_progress(dataset)
13891398
assert progress == {"total": len(records), "completed": len(records)}
13901399

1400+
async def test_get_dataset_progress_for_draft_dataset(self, search_engine: BaseElasticAndOpenSearchEngine):
1401+
dataset = await DatasetFactory.create(status=DatasetStatus.draft)
1402+
progress = await search_engine.get_dataset_progress(dataset)
1403+
assert progress == {}
1404+
13911405
@pytest.mark.parametrize(
13921406
("property_name", "expected_metrics"),
13931407
[

0 commit comments

Comments
 (0)