Skip to content

Commit 1e1eabf

Browse files
committed
backwards compatiblity nightmare
1 parent c07c4f8 commit 1e1eabf

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

services/storage/src/simcore_service_storage/models.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import urllib.parse
33
from dataclasses import dataclass
4-
from typing import Literal, NamedTuple, Self
4+
from typing import Any, Literal, NamedTuple
55
from uuid import UUID
66

77
import arrow
@@ -186,14 +186,18 @@ def convert_from_lower_case(cls, v: str) -> str:
186186
return f"{v}".upper()
187187
return v
188188

189-
@model_validator(mode="after")
190-
def when_directory_force_link_type_and_file_size(self) -> Self:
191-
if self.is_directory is True:
189+
@model_validator(mode="before")
190+
@classmethod
191+
def when_directory_force_link_type_and_file_size(cls, data: Any) -> Any:
192+
assert isinstance(data, dict)
193+
194+
if bool(data.get("is_directory", False)) is True:
192195
# sets directory size by default to undefined
193-
self.file_size = None
196+
if int(data.get("file_size", -1)) < 0:
197+
data["file_size"] = None
194198
# only 1 link will be returned manged by the uploader
195-
self.link_type = LinkType.S3
196-
return self
199+
data["link_type"] = LinkType.S3.value
200+
return data
197201

198202
@property
199203
def is_v1_upload(self) -> bool:

services/storage/tests/unit/test_handlers_files.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,16 +1199,18 @@ async def test_copy_as_soft_link(
11991199

12001200
# now let's try with whatever link id
12011201
file, original_file_uuid = await upload_file(
1202-
TypeAdapter(ByteSize, "10Mib")
1203-
).validate_python(faker.file_name())
1202+
TypeAdapter(ByteSize).validate_python("10Mib"), faker.file_name()
1203+
)
12041204
url = (
12051205
client.app.router["copy_as_soft_link"]
12061206
.url_for(
12071207
file_id=urllib.parse.quote(original_file_uuid, safe=""),
12081208
)
12091209
.with_query(user_id=user_id)
12101210
)
1211-
link_id = SimcoreS3FileID(f"api/{node_id}/{faker.file_name()}")
1211+
link_id = TypeAdapter(SimcoreS3FileID).validate_python(
1212+
f"api/{node_id}/{faker.file_name()}"
1213+
)
12121214
response = await client.post(
12131215
f"{url}", json=jsonable_encoder(SoftCopyBody(link_id=link_id))
12141216
)
@@ -1442,12 +1444,12 @@ async def test_listing_with_project_id_filter(
14421444
project, src_projects_list = await random_project_with_files(
14431445
num_nodes=1,
14441446
file_sizes=(ByteSize(1),),
1445-
file_checksums=(SHA256Str(faker.sha256()),),
1447+
file_checksums=(TypeAdapter(SHA256Str).validate_python(faker.sha256()),),
14461448
)
14471449
_, _ = await random_project_with_files(
14481450
num_nodes=1,
14491451
file_sizes=(ByteSize(1),),
1450-
file_checksums=(SHA256Str(faker.sha256()),),
1452+
file_checksums=(TypeAdapter(SHA256Str).validate_python(faker.sha256()),),
14511453
)
14521454
assert len(src_projects_list.keys()) > 0
14531455
node_id = next(iter(src_projects_list.keys()))

0 commit comments

Comments
 (0)