From 764461d81360cea28df8664ca5c3393028d7034f Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 08:39:14 +0200 Subject: [PATCH 1/6] Validate model key and fix error handling --- .../new/internal/backends/hosted_neptune_backend.py | 2 ++ neptune/new/internal/init/model.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/neptune/new/internal/backends/hosted_neptune_backend.py b/neptune/new/internal/backends/hosted_neptune_backend.py index 8adfe6fdb..a763ddb7e 100644 --- a/neptune/new/internal/backends/hosted_neptune_backend.py +++ b/neptune/new/internal/backends/hosted_neptune_backend.py @@ -362,6 +362,7 @@ def create_run( additional_params=additional_params, ) + @with_api_exceptions_handler def create_model(self, project_id: UniqueId, key: str = "") -> ApiExperiment: additional_params = { "key": key, @@ -374,6 +375,7 @@ def create_model(self, project_id: UniqueId, key: str = "") -> ApiExperiment: additional_params=additional_params, ) + @with_api_exceptions_handler def create_model_version( self, project_id: UniqueId, model_id: UniqueId ) -> ApiExperiment: diff --git a/neptune/new/internal/init/model.py b/neptune/new/internal/init/model.py index ac036e244..bf45c2039 100644 --- a/neptune/new/internal/init/model.py +++ b/neptune/new/internal/init/model.py @@ -14,6 +14,7 @@ # limitations under the License. # +import re import threading from typing import Optional @@ -64,6 +65,15 @@ def init_model( # make mode proper Enum instead of string mode = Mode(mode) + if len(key) > 10: + raise ValueError("Model key cannot be longer than 10 characters") + if key != key.upper(): + raise ValueError("Model key cannot contain lowercase letters") + if not re.match(r"^[A-Z0-9]{1,10}$", key): + raise ValueError("Model key should contain only capital letters and digits") + if re.match(r"^[0-9]*$", key): + raise ValueError("Model key cannot consist of digits only") + if mode == Mode.OFFLINE: raise NeptuneException("Model can't be initialized in OFFLINE mode") From ff1772dc26817637d98ca15c4b388bf1c6d6c8e9 Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 08:49:10 +0200 Subject: [PATCH 2/6] Fix --- neptune/new/internal/init/model.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/neptune/new/internal/init/model.py b/neptune/new/internal/init/model.py index bf45c2039..c13ad0bea 100644 --- a/neptune/new/internal/init/model.py +++ b/neptune/new/internal/init/model.py @@ -65,14 +65,15 @@ def init_model( # make mode proper Enum instead of string mode = Mode(mode) - if len(key) > 10: - raise ValueError("Model key cannot be longer than 10 characters") - if key != key.upper(): - raise ValueError("Model key cannot contain lowercase letters") - if not re.match(r"^[A-Z0-9]{1,10}$", key): - raise ValueError("Model key should contain only capital letters and digits") - if re.match(r"^[0-9]*$", key): - raise ValueError("Model key cannot consist of digits only") + if key: + if len(key) > 10: + raise ValueError("Model key cannot be longer than 10 characters") + if key != key.upper(): + raise ValueError("Model key cannot contain lowercase letters") + if not re.match(r"^[A-Z0-9]{1,10}$", key): + raise ValueError("Model key should contain only capital letters and digits") + if re.match(r"^[0-9]*$", key): + raise ValueError("Model key cannot consist of digits only") if mode == Mode.OFFLINE: raise NeptuneException("Model can't be initialized in OFFLINE mode") From 72c787d004bc444f4d46f573f8ceebfa7e2f6740 Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 08:56:21 +0200 Subject: [PATCH 3/6] Add commment --- neptune/new/internal/init/model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neptune/new/internal/init/model.py b/neptune/new/internal/init/model.py index c13ad0bea..7dfcdab85 100644 --- a/neptune/new/internal/init/model.py +++ b/neptune/new/internal/init/model.py @@ -65,6 +65,8 @@ def init_model( # make mode proper Enum instead of string mode = Mode(mode) + # TODO: Do not duplicate validation logic from server. + # Instead, design server-side Validation Errors that can be pretty printed in client. if key: if len(key) > 10: raise ValueError("Model key cannot be longer than 10 characters") From 86102d23fc97540732cae6c1505600973c5549ed Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 09:10:29 +0200 Subject: [PATCH 4/6] Fix --- neptune/new/internal/init/model.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/neptune/new/internal/init/model.py b/neptune/new/internal/init/model.py index 7dfcdab85..7353204d5 100644 --- a/neptune/new/internal/init/model.py +++ b/neptune/new/internal/init/model.py @@ -65,18 +65,6 @@ def init_model( # make mode proper Enum instead of string mode = Mode(mode) - # TODO: Do not duplicate validation logic from server. - # Instead, design server-side Validation Errors that can be pretty printed in client. - if key: - if len(key) > 10: - raise ValueError("Model key cannot be longer than 10 characters") - if key != key.upper(): - raise ValueError("Model key cannot contain lowercase letters") - if not re.match(r"^[A-Z0-9]{1,10}$", key): - raise ValueError("Model key should contain only capital letters and digits") - if re.match(r"^[0-9]*$", key): - raise ValueError("Model key cannot consist of digits only") - if mode == Mode.OFFLINE: raise NeptuneException("Model can't be initialized in OFFLINE mode") From cd713c1093ae328d48799361eceeb8c21cf7cecc Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 09:10:57 +0200 Subject: [PATCH 5/6] Fix --- neptune/new/internal/init/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neptune/new/internal/init/model.py b/neptune/new/internal/init/model.py index 7353204d5..ac036e244 100644 --- a/neptune/new/internal/init/model.py +++ b/neptune/new/internal/init/model.py @@ -14,7 +14,6 @@ # limitations under the License. # -import re import threading from typing import Optional From b4d484cfc71100ade45f07496f32f3e74d500c28 Mon Sep 17 00:00:00 2001 From: wajcha Date: Thu, 12 May 2022 09:15:17 +0200 Subject: [PATCH 6/6] Changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af5cd7c3..7d7acb3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ -## [UNRELEASED] neptune-client 0.16.2 +## [UNRELEASED] neptune-client 0.16.3 + + +## neptune-client 0.16.2 ## Features - Sync only offline runs inside '.neptune' directory CLI flag ([#894](https://github.com/neptune-ai/neptune-client/pull/894)) +## Fixes +- Fix handling of server errors ([#896](https://github.com/neptune-ai/neptune-client/pull/896)) + ## neptune-client 0.16.1 ## Features