Skip to content

Commit

Permalink
backwards compatiblity nightmare
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Oct 25, 2024
1 parent 7fbb3f1 commit 6b4789c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 11 additions & 7 deletions services/storage/src/simcore_service_storage/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import urllib.parse
from dataclasses import dataclass
from typing import Literal, NamedTuple, Self
from typing import Any, Literal, NamedTuple
from uuid import UUID

import arrow
Expand Down Expand Up @@ -186,14 +186,18 @@ def convert_from_lower_case(cls, v: str) -> str:
return f"{v}".upper()
return v

@model_validator(mode="after")
def when_directory_force_link_type_and_file_size(self) -> Self:
if self.is_directory is True:
@model_validator(mode="before")
@classmethod
def when_directory_force_link_type_and_file_size(cls, data: Any) -> Any:
assert isinstance(data, dict)

if bool(data.get("is_directory", False)) is True:
# sets directory size by default to undefined
self.file_size = None
if int(data.get("file_size", -1)) < 0:
data["file_size"] = None
# only 1 link will be returned manged by the uploader
self.link_type = LinkType.S3
return self
data["link_type"] = LinkType.S3.value
return data

@property
def is_v1_upload(self) -> bool:
Expand Down
12 changes: 7 additions & 5 deletions services/storage/tests/unit/test_handlers_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,16 +1199,18 @@ async def test_copy_as_soft_link(

# now let's try with whatever link id
file, original_file_uuid = await upload_file(
TypeAdapter(ByteSize, "10Mib")
).validate_python(faker.file_name())
TypeAdapter(ByteSize).validate_python("10Mib"), faker.file_name()
)
url = (
client.app.router["copy_as_soft_link"]
.url_for(
file_id=urllib.parse.quote(original_file_uuid, safe=""),
)
.with_query(user_id=user_id)
)
link_id = SimcoreS3FileID(f"api/{node_id}/{faker.file_name()}")
link_id = TypeAdapter(SimcoreS3FileID).validate_python(
f"api/{node_id}/{faker.file_name()}"
)
response = await client.post(
f"{url}", json=jsonable_encoder(SoftCopyBody(link_id=link_id))
)
Expand Down Expand Up @@ -1442,12 +1444,12 @@ async def test_listing_with_project_id_filter(
project, src_projects_list = await random_project_with_files(
num_nodes=1,
file_sizes=(ByteSize(1),),
file_checksums=(SHA256Str(faker.sha256()),),
file_checksums=(TypeAdapter(SHA256Str).validate_python(faker.sha256()),),
)
_, _ = await random_project_with_files(
num_nodes=1,
file_sizes=(ByteSize(1),),
file_checksums=(SHA256Str(faker.sha256()),),
file_checksums=(TypeAdapter(SHA256Str).validate_python(faker.sha256()),),
)
assert len(src_projects_list.keys()) > 0
node_id = next(iter(src_projects_list.keys()))
Expand Down

0 comments on commit 6b4789c

Please sign in to comment.