Skip to content

Commit 756678d

Browse files
committed
Fix error handling for non-existing project
1 parent d6c56fd commit 756678d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

comet_for_mlflow/comet_for_mlflow.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from comet_ml.comet import format_url
3939
from comet_ml.config import get_api_key, get_config
4040
from comet_ml.connection import Reporting, get_comet_api_client, url_join
41-
from comet_ml.exceptions import CometRestApiException, NotFound
41+
from comet_ml.exceptions import CometRestApiException
4242
from comet_ml.offline import upload_single_offline_experiment
4343
from mlflow.entities.run_tag import RunTag
4444
from mlflow.entities.view_type import ViewType
@@ -530,17 +530,15 @@ def create_and_save_comet_project(self, exp, tag_name):
530530
project_name = get_comet_project_name(self.store, exp.name)
531531

532532
# Check if the project exists already
533-
try:
534-
project = self.api_client.get_project(self.workspace, project_name)
535-
if not project:
536-
raise NotFound("POST", {})
537-
project_id = project["projectId"]
538-
except NotFound:
533+
project = self.api_client.get_project(self.workspace, project_name)
534+
if not project:
539535
project = self.api_client.create_project(
540536
self.workspace, project_name, public=False
541537
)
542538

543539
project_id = project["projectId"]
540+
else:
541+
project_id = project["projectId"]
544542

545543
# Save the project id to the experiment tags
546544
self.store.set_experiment_tag(exp.experiment_id, RunTag(tag_name, project_id))
@@ -557,15 +555,12 @@ def get_or_create_comet_project(self, exp):
557555
project_id = exp.tags[tag_name]
558556

559557
# Check if the project exists
560-
try:
561-
project = self.api_client.get_project_by_id(project_id)
562-
if not project:
563-
raise NotFound("POST", {})
564-
return project["projectName"]
565-
except (NotFound):
558+
project = self.api_client.get_project_by_id(project_id)
559+
if not project:
566560
# A previous project ID has been saved but don't exists anymore (at
567561
# least in this environment), recreate it
568562
return self.create_and_save_comet_project(exp, tag_name)
563+
return project["projectName"]
569564
else:
570565
return self.create_and_save_comet_project(exp, tag_name)
571566

0 commit comments

Comments
 (0)