Skip to content

Commit 2f80951

Browse files
authored
Merge pull request #763 from Labelbox/lgluszek/CCV-2223
[CCV-2223] Dont allow to call setup_editor multiple times
2 parents 0f38024 + 4b3a739 commit 2f80951

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

labelbox/schema/project.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from labelbox import utils
1414
from labelbox.exceptions import (InvalidQueryError, LabelboxError,
15-
ProcessingWaitTimeout)
15+
ProcessingWaitTimeout, ResourceConflict)
1616
from labelbox.orm import query
1717
from labelbox.orm.db_object import DbObject, Deletable, Updateable
1818
from labelbox.orm.model import Entity, Field, Relationship
@@ -511,6 +511,9 @@ def setup_editor(self, ontology) -> None:
511511
Args:
512512
ontology (Ontology): The ontology to attach to the project
513513
"""
514+
if self.labeling_frontend() is not None:
515+
raise ResourceConflict("Editor is already set up.")
516+
514517
labeling_frontend = next(
515518
self.client.get_labeling_frontends(
516519
where=Entity.LabelingFrontend.name == "Editor"))
@@ -550,6 +553,9 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
550553
to `str` using `json.dumps`.
551554
"""
552555

556+
if self.labeling_frontend() is not None:
557+
raise ResourceConflict("Editor is already set up.")
558+
553559
if not isinstance(labeling_frontend_options, str):
554560
labeling_frontend_options = json.dumps(labeling_frontend_options)
555561

tests/integration/test_project_setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from labelbox import LabelingFrontend
9-
from labelbox.exceptions import InvalidQueryError
9+
from labelbox.exceptions import InvalidQueryError, ResourceConflict
1010

1111

1212
def simple_ontology():
@@ -67,3 +67,12 @@ def test_project_editor_setup(client, project, rand_gen):
6767
time.sleep(3) # Search takes a second
6868
assert [ontology.name for ontology in client.get_ontologies(ontology_name)
6969
] == [ontology_name]
70+
71+
72+
def test_project_editor_setup_cant_call_multiple_times(client, project,
73+
rand_gen):
74+
ontology_name = f"test_project_editor_setup_ontology_name-{rand_gen(str)}"
75+
ontology = client.create_ontology(ontology_name, simple_ontology())
76+
project.setup_editor(ontology)
77+
with pytest.raises(ResourceConflict):
78+
project.setup_editor(ontology)

0 commit comments

Comments
 (0)