From f9e081ae2f3636904b5e9ef4a22f7f161a484385 Mon Sep 17 00:00:00 2001 From: Val Brodsky Date: Wed, 10 Jul 2024 14:08:41 -0400 Subject: [PATCH 1/2] Update ontology check to raise exception earlier to prevent creation of editor without an ontology --- libs/labelbox/src/labelbox/schema/project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index b552a945b..37dba51b0 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -790,6 +790,9 @@ def connect_ontology(self, ontology) -> None: Args: ontology (Ontology): The ontology to attach to the project """ + if not self.is_empty_ontology(): + raise ValueError("Ontology already connected to project.") + if self.labeling_frontend( ) is None: # Chat evaluation projects are automatically set up via the same api that creates a project self._connect_default_labeling_front_end(ontology_as_dict={ @@ -797,9 +800,6 @@ def connect_ontology(self, ontology) -> None: "classifications": [] }) - if not self.is_empty_ontology(): - raise ValueError("Ontology already connected to project.") - query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){ project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}""" self.client.execute(query_str, { From a3abefa3b4bc99fb1d5fd32a56acdfaabcd5ec71 Mon Sep 17 00:00:00 2001 From: Val Brodsky Date: Wed, 10 Jul 2024 14:09:48 -0400 Subject: [PATCH 2/2] Update Project setup logic not to skip creation of ontology if an editor exists --- libs/labelbox/src/labelbox/schema/project.py | 16 ++++++++-------- .../tests/data/annotation_import/conftest.py | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 37dba51b0..1fd87c7e5 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -832,19 +832,19 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None: """) return - if self.labeling_frontend( - ) is None: # Chat evaluation projects are automatically set up via the same api that creates a project - self._connect_default_labeling_front_end(labeling_frontend_options) + self._connect_default_labeling_front_end(labeling_frontend_options) timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") self.update(setup_complete=timestamp) def _connect_default_labeling_front_end(self, ontology_as_dict: dict): - warnings.warn("Connecting default labeling editor for the project.") - labeling_frontend = next( - self.client.get_labeling_frontends( - where=Entity.LabelingFrontend.name == "Editor")) - self.labeling_frontend.connect(labeling_frontend) + labeling_frontend = self.labeling_frontend() + if labeling_frontend is None: # Chat evaluation projects are automatically set up via the same api that creates a project + warnings.warn("Connecting default labeling editor for the project.") + labeling_frontend = next( + self.client.get_labeling_frontends( + where=Entity.LabelingFrontend.name == "Editor")) + self.labeling_frontend.connect(labeling_frontend) if not isinstance(ontology_as_dict, str): labeling_frontend_options_str = json.dumps(ontology_as_dict) diff --git a/libs/labelbox/tests/data/annotation_import/conftest.py b/libs/labelbox/tests/data/annotation_import/conftest.py index df911da10..9ef66e61e 100644 --- a/libs/labelbox/tests/data/annotation_import/conftest.py +++ b/libs/labelbox/tests/data/annotation_import/conftest.py @@ -619,7 +619,6 @@ def configured_project(client, initial_dataset, ontology, rand_gen, image_url): client.get_labeling_frontends( where=LabelingFrontend.name == "editor"))[0] project.setup(editor, ontology) - data_row_ids = [] ontologies = ontology["tools"] + ontology["classifications"]