From a1f79d20be59d1ec02b2bfc79d308779e890a501 Mon Sep 17 00:00:00 2001 From: fynnbe Date: Thu, 14 Nov 2024 00:12:05 +0100 Subject: [PATCH] include all defaults for collection_draft.json --- bioimageio_collection_backoffice/common.py | 28 ------------------- .../db_structure/version_info.py | 6 +--- .../remote_collection.py | 4 ++- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/bioimageio_collection_backoffice/common.py b/bioimageio_collection_backoffice/common.py index 9bd9e0b..c111f0c 100644 --- a/bioimageio_collection_backoffice/common.py +++ b/bioimageio_collection_backoffice/common.py @@ -1,8 +1,4 @@ -from typing import Any, ClassVar, Dict, FrozenSet, Union - import pydantic -from pydantic_core import PydanticUndefined -from typing_extensions import LiteralString class Node( @@ -15,27 +11,3 @@ class Node( validate_default=False, ): """""" # avoid inheriting docstring from `pydantic.BaseModel` - - fields_to_set_explicitly: ClassVar[FrozenSet[LiteralString]] = frozenset() - """set set these fields explicitly with their default value if they are not set, - such that they are always included even when dumping with 'exlude_unset'""" - - @pydantic.model_validator(mode="before") - @classmethod - def set_fields_explicitly( - cls, data: Union[Any, Dict[str, Any]] - ) -> Union[Any, Dict[str, Any]]: - if isinstance(data, dict): - for name in cls.fields_to_set_explicitly: - if ( - name not in data - and name in cls.model_fields - and ( - (field_info := cls.model_fields[name]).default - is not PydanticUndefined - or field_info.default_factory is not None - ) - ): - data[name] = field_info.get_default(call_default_factory=True) - - return data # pyright: ignore[reportUnknownVariableType] diff --git a/bioimageio_collection_backoffice/db_structure/version_info.py b/bioimageio_collection_backoffice/db_structure/version_info.py index a59a726..3862786 100644 --- a/bioimageio_collection_backoffice/db_structure/version_info.py +++ b/bioimageio_collection_backoffice/db_structure/version_info.py @@ -3,7 +3,6 @@ from datetime import datetime from typing import ( ClassVar, - FrozenSet, List, Literal, Optional, @@ -12,16 +11,13 @@ ) import pydantic -from typing_extensions import Annotated, LiteralString +from typing_extensions import Annotated from .._settings import settings from ..common import Node class _StatusBase(Node, frozen=True): - fields_to_set_explicitly: ClassVar[FrozenSet[LiteralString]] = frozenset( - {"name", "step", "num_steps", "description"} - ) timestamp: datetime = pydantic.Field(default_factory=datetime.now) run_url: Optional[str] = settings.run_url diff --git a/bioimageio_collection_backoffice/remote_collection.py b/bioimageio_collection_backoffice/remote_collection.py index 731010a..7378c5e 100644 --- a/bioimageio_collection_backoffice/remote_collection.py +++ b/bioimageio_collection_backoffice/remote_collection.py @@ -466,7 +466,9 @@ def generate_collection_json( if collection_entries or not list(self.client.ls(collection_output_file_name)): self.client.put_json( collection_output_file_name, - collection.model_dump(mode="json", exclude_defaults=True), + collection.model_dump( + mode="json", exclude_defaults=mode == "published" + ), ) else: logger.error(