Skip to content

Commit 32a5453

Browse files
continue upgrading
1 parent 2cddbd8 commit 32a5453

File tree

7 files changed

+51
-28
lines changed

7 files changed

+51
-28
lines changed

packages/models-library/src/models_library/errors_classes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
from pydantic.errors import PydanticErrorMixin
24

35

@@ -14,8 +16,8 @@ def __new__(cls, *_args, **_kwargs):
1416
cls.code = cls._get_full_class_name() # type: ignore[assignment]
1517
return super().__new__(cls)
1618

17-
def __init__(self, *_args, **kwargs) -> None:
18-
self.__dict__ = kwargs
19+
def __init__(self, **ctx: Any) -> None:
20+
self.__dict__ = ctx
1921
super().__init__(message=self._build_message(), code=self.code)
2022

2123
def __str__(self) -> str:

packages/simcore-sdk/src/simcore_sdk/node_data/data_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from models_library.projects import ProjectID
77
from models_library.projects_nodes_io import NodeID, StorageFileID
88
from models_library.users import UserID
9-
from pydantic import ByteSize, parse_obj_as
9+
from pydantic import ByteSize, TypeAdapter
1010
from servicelib.archiving_utils import unarchive_dir
1111
from servicelib.logging_utils import log_context
1212
from servicelib.progress_bar import ProgressBarData
@@ -25,7 +25,9 @@ def __create_s3_object_key(
2525
project_id: ProjectID, node_uuid: NodeID, file_path: Path | str
2626
) -> StorageFileID:
2727
file_name = file_path.name if isinstance(file_path, Path) else file_path
28-
return parse_obj_as(StorageFileID, f"{project_id}/{node_uuid}/{file_name}") # type: ignore[arg-type]
28+
return TypeAdapter(StorageFileID).validate_python(
29+
f"{project_id}/{node_uuid}/{file_name}"
30+
)
2931

3032

3133
def __get_s3_name(path: Path, *, is_archive: bool) -> str:

packages/simcore-sdk/src/simcore_sdk/node_ports_v2/port.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ class SetKWargs:
7878
class Port(BaseServiceIOModel):
7979
key: ServicePortKey
8080
widget: dict[str, Any] | None = None
81-
default_value: DataItemValue | None = Field(None, alias="defaultValue")
81+
default_value: DataItemValue | None = Field(
82+
None, alias="defaultValue", union_mode="left_to_right"
83+
)
8284

83-
value: DataItemValue | None = Field(None, validate_default=True, union_mode="left_to_right")
85+
value: DataItemValue | None = Field(
86+
None, validate_default=True, union_mode="left_to_right"
87+
)
8488

8589
# Different states of "value"
8690
# - e.g. typically after resolving a port's link, a download link, ...
8791
# - lazy evaluation using get_* members
8892
# - used to run validation & conversion of resolved PortContentTypes values
8993
# - excluded from all model export
90-
value_item: ItemValue | None = Field(None, exclude=True)
91-
value_concrete: ItemConcreteValue | None = Field(None, exclude=True)
94+
value_item: ItemValue | None = Field(None, exclude=True, union_mode="left_to_right")
95+
value_concrete: ItemConcreteValue | None = Field(
96+
None, exclude=True, union_mode="left_to_right"
97+
)
9298

9399
# Function to convert from ItemValue -> ItemConcreteValue
94100
_py_value_converter: Callable[[Any], ItemConcreteValue] = PrivateAttr()

packages/simcore-sdk/src/simcore_sdk/node_ports_v2/port_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# - Use 'code' to discriminate port_validation errors
2323

2424

25-
class PortValueError(OsparcErrorMixin, RuntimeError):
25+
class PortValueError(OsparcErrorMixin, ValueError):
2626
code = "port_validation.schema_error"
2727
msg_template = "Invalid value in port {port_key!r}: {schema_error_message}"
2828

@@ -37,7 +37,7 @@ def __init__(self, *, port_key: str, schema_error: JsonSchemaValidationError):
3737
)
3838

3939

40-
class PortUnitError(OsparcErrorMixin, RuntimeError):
40+
class PortUnitError(OsparcErrorMixin, ValueError):
4141
code = "port_validation.unit_error"
4242
msg_template = "Invalid unit in port {port_key!r}: {pint_error_msg}"
4343

packages/simcore-sdk/tests/unit/test_node_ports_v2_port_mapping.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def test_validate_port_value_against_schema(fake_port_meta: dict[str, Any]):
110110

111111
assert error["loc"] == ("value",)
112112
assert "-2 is less than the minimum of 0" in error["msg"]
113-
assert error["type"] == "value_error.port_validation.schema_error"
113+
assert error["type"] == "value_error"
114114

115115
assert "ctx" in error
116-
assert error["ctx"]["port_key"] == "port_1"
116+
assert error["ctx"]["error"].port_key == "port_1"
117117

118-
schema_error_message = error["ctx"]["schema_error_message"]
119-
schema_error_path = error["ctx"]["schema_error_path"]
118+
schema_error_message = error["ctx"]["error"].schema_error_message
119+
schema_error_path = error["ctx"]["error"].schema_error_path
120120

121121
assert schema_error_message in error["msg"]
122122
assert schema_error_path == deque([1])
@@ -152,7 +152,7 @@ def test_validate_iolist_against_schema(fake_port_meta: dict[str, Any]):
152152
# ----
153153

154154
with pytest.raises(ValidationError) as err_info:
155-
InputsList.parse_obj({p["key"]: p for p in ports})
155+
InputsList.model_validate({p["key"]: p for p in ports})
156156

157157
# ---
158158
assert isinstance(err_info.value, ValidationError)
@@ -162,14 +162,13 @@ def test_validate_iolist_against_schema(fake_port_meta: dict[str, Any]):
162162
for error in err_info.value.errors():
163163
error_loc = error["loc"]
164164
assert "ctx" in error
165-
port_key = error["ctx"].get("port_key")
165+
port_key = error["ctx"]["error"].port_key
166166

167167
# path hierachy
168-
assert error_loc[0] == "__root__", f"{error_loc=}"
169-
assert error_loc[1] == port_key, f"{error_loc=}"
170-
assert error_loc[-1] == "value", f"{error_loc=}"
168+
assert error_loc[0] == port_key, f"{error_loc=}"
169+
assert error_loc[1] == "value", f"{error_loc=}"
171170

172-
assert error["type"] == "value_error.port_validation.schema_error"
171+
assert error["type"] == "value_error"
173172
port_with_errors.append(port_key)
174173
pprint(error)
175174

packages/simcore-sdk/tests/unit/test_node_ports_v2_port_validation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def test_port_with_units_and_constraints(mocker):
245245
print(validation_error)
246246

247247
assert validation_error["loc"] == ("value",) # starts with value,!
248-
assert validation_error["type"] == "value_error.port_validation.schema_error"
248+
assert validation_error["type"] == "value_error"
249249
assert "-3.14 is less than the minimum of 0" in validation_error["msg"]
250250

251251
# inits with None + set_value
@@ -257,8 +257,6 @@ async def test_port_with_units_and_constraints(mocker):
257257
with pytest.raises(ValidationError) as exc_info:
258258
await port.set_value(-3.14)
259259

260-
assert exc_info.value.errors()[0] == validation_error
261-
262260

263261
def test_incident__port_validator_check_value():
264262
# SEE incident https://git.speag.com/oSparc/e2e-testing/-/issues/1)

packages/simcore-sdk/tests/unit/test_storage_client.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,28 @@ def test_mode_ports_storage_without_auth(
362362
[
363363
(True, _HTTP_URL, _HTTPS_URL),
364364
(False, _HTTP_URL, _HTTP_URL),
365-
(True, TypeAdapter(AnyUrl).validate_python(_HTTP_URL), _HTTPS_URL),
366-
(False, TypeAdapter(AnyUrl).validate_python(_HTTP_URL), _HTTP_URL),
365+
(
366+
True,
367+
str(TypeAdapter(AnyUrl).validate_python(_HTTP_URL)).rstrip("/"),
368+
_HTTPS_URL,
369+
),
370+
(
371+
False,
372+
str(TypeAdapter(AnyUrl).validate_python(_HTTP_URL)).rstrip("/"),
373+
_HTTP_URL,
374+
),
367375
(True, _HTTPS_URL, _HTTPS_URL),
368376
(False, _HTTPS_URL, _HTTPS_URL),
369-
(True, TypeAdapter(AnyUrl).validate_python(_HTTPS_URL), _HTTPS_URL),
370-
(False, TypeAdapter(AnyUrl).validate_python(_HTTPS_URL), _HTTPS_URL),
377+
(
378+
True,
379+
str(TypeAdapter(AnyUrl).validate_python(_HTTPS_URL)).rstrip("/"),
380+
_HTTPS_URL,
381+
),
382+
(
383+
False,
384+
str(TypeAdapter(AnyUrl).validate_python(_HTTPS_URL)).rstrip("/"),
385+
_HTTPS_URL,
386+
),
371387
(True, "http://http", "https://http"),
372388
(True, "https://http", "https://http"),
373389
],
@@ -382,4 +398,4 @@ def test__get_secure_link(
382398
is_storage_secure.cache_clear()
383399

384400
setenvs_from_dict(monkeypatch, {"STORAGE_SECURE": "1" if storage_secure else "0"})
385-
assert _get_https_link_if_storage_secure(provided) == expected
401+
assert _get_https_link_if_storage_secure(str(provided)) == expected

0 commit comments

Comments
 (0)