Skip to content

Commit f351ee2

Browse files
authored
Vb/fix create ontology for project setup (#1722)
1 parent 2b85435 commit f351ee2

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,16 @@ def connect_ontology(self, ontology) -> None:
790790
Args:
791791
ontology (Ontology): The ontology to attach to the project
792792
"""
793+
if not self.is_empty_ontology():
794+
raise ValueError("Ontology already connected to project.")
795+
793796
if self.labeling_frontend(
794797
) is None: # Chat evaluation projects are automatically set up via the same api that creates a project
795798
self._connect_default_labeling_front_end(ontology_as_dict={
796799
"tools": [],
797800
"classifications": []
798801
})
799802

800-
if not self.is_empty_ontology():
801-
raise ValueError("Ontology already connected to project.")
802-
803803
query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){
804804
project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}"""
805805
self.client.execute(query_str, {
@@ -832,19 +832,19 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
832832
""")
833833
return
834834

835-
if self.labeling_frontend(
836-
) is None: # Chat evaluation projects are automatically set up via the same api that creates a project
837-
self._connect_default_labeling_front_end(labeling_frontend_options)
835+
self._connect_default_labeling_front_end(labeling_frontend_options)
838836

839837
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
840838
self.update(setup_complete=timestamp)
841839

842840
def _connect_default_labeling_front_end(self, ontology_as_dict: dict):
843-
warnings.warn("Connecting default labeling editor for the project.")
844-
labeling_frontend = next(
845-
self.client.get_labeling_frontends(
846-
where=Entity.LabelingFrontend.name == "Editor"))
847-
self.labeling_frontend.connect(labeling_frontend)
841+
labeling_frontend = self.labeling_frontend()
842+
if labeling_frontend is None: # Chat evaluation projects are automatically set up via the same api that creates a project
843+
warnings.warn("Connecting default labeling editor for the project.")
844+
labeling_frontend = next(
845+
self.client.get_labeling_frontends(
846+
where=Entity.LabelingFrontend.name == "Editor"))
847+
self.labeling_frontend.connect(labeling_frontend)
848848

849849
if not isinstance(ontology_as_dict, str):
850850
labeling_frontend_options_str = json.dumps(ontology_as_dict)

libs/labelbox/tests/data/annotation_import/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
619619
client.get_labeling_frontends(
620620
where=LabelingFrontend.name == "editor"))[0]
621621
project.setup(editor, ontology)
622-
623622
data_row_ids = []
624623

625624
ontologies = ontology["tools"] + ontology["classifications"]

0 commit comments

Comments
 (0)