Skip to content

Commit

Permalink
fix(#1081): prevent add records of different task (#1085)
Browse files Browse the repository at this point in the history
* fix(#1081): prevent add records of different task

* test: add tests

(cherry picked from commit 45d0ce6)
  • Loading branch information
frascuchon committed Feb 2, 2022
1 parent f26c79c commit 5296e52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rubrix/server/datasets/service.py
Expand Up @@ -191,6 +191,7 @@ def update(
data: UpdateDatasetRequest,
user: User,
workspace: Optional[str],
task: Optional[str] = None,
) -> Dataset:
"""
Updates an existing dataset. Fields in update data are
Expand All @@ -206,13 +207,15 @@ def update(
The current user
workspace:
The workspace where dataset belongs to
task:
If provided, is used to match the existing dataset
Returns
-------
The updated dataset
"""

found = self.find_by_name(name, task=None, user=user, workspace=workspace)
found = self.find_by_name(name, task=task, user=user, workspace=workspace)

data.tags = {**found.tags, **data.tags}
data.metadata = {**found.metadata, **data.metadata}
Expand Down Expand Up @@ -257,6 +260,7 @@ def upsert(
data=UpdateDatasetRequest(tags=dataset.tags, metadata=dataset.metadata),
user=user,
workspace=workspace,
task=task,
)
except EntityNotFoundError:
return self.create(
Expand Down
17 changes: 17 additions & 0 deletions tests/functional_tests/test_log_for_text_classification.py
Expand Up @@ -92,3 +92,20 @@ def test_logging_with_metadata_limits_exceeded(monkeypatch):
expected_record.metadata["new_key"] = "value"
with pytest.raises(BadRequestApiError):
rubrix.log(expected_record, name=dataset)


def test_log_with_other_task(monkeypatch):
mocking_client(monkeypatch, client)
dataset = "test_log_with_other_task"

rubrix.delete(dataset)
record = TextClassificationRecord(
inputs="The input text",
)
rubrix.log(record, name=dataset)

with pytest.raises(BadRequestApiError):
rubrix.log(
TokenClassificationRecord(text="The text", tokens=["The", "text"]),
name=dataset,
)

0 comments on commit 5296e52

Please sign in to comment.