From 29b20f588c28f01144f615a2ad41c43f7aecc3c5 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Fri, 29 Sep 2023 13:36:02 +0200 Subject: [PATCH 1/2] fix: mark type readonly, remove setter --- tests/dataset_fields_test.py | 8 +++++++- tools/model-generation/templates/dataset_fields.py.jinja | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/dataset_fields_test.py b/tests/dataset_fields_test.py index 7dea8fd7..0a12e7c9 100644 --- a/tests/dataset_fields_test.py +++ b/tests/dataset_fields_test.py @@ -27,6 +27,8 @@ # Fields whose types are not supported by hypothesis. # E.g. because they contain `Any`. _UNGENERATABLE_FIELDS = ("job_parameters", "meta") +# Fields that are readonly, but still required in the constructor. +_NOT_SETTABLE_FIELDS = ("type",) def test_init_dataset_with_only_type(): @@ -107,7 +109,11 @@ def test_can_init_writable_fields(field, data): @pytest.mark.parametrize( "field", - (f for f in Dataset.fields(read_only=False) if f.name not in _UNGENERATABLE_FIELDS), + ( + f + for f in Dataset.fields(read_only=False) + if f.name not in _UNGENERATABLE_FIELDS and f.name not in _NOT_SETTABLE_FIELDS + ), ids=lambda f: f.name, ) @given(st.data()) diff --git a/tools/model-generation/templates/dataset_fields.py.jinja b/tools/model-generation/templates/dataset_fields.py.jinja index 45e05268..39524aa0 100644 --- a/tools/model-generation/templates/dataset_fields.py.jinja +++ b/tools/model-generation/templates/dataset_fields.py.jinja @@ -193,11 +193,6 @@ class DatasetBase: """Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.""" return self._type - @type.setter - def type(self, type: Union[DatasetType, Literal["raw", "derived"]]) -> None: - """Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.""" - self._type = DatasetType(type) - @staticmethod def _prepare_fields_from_download( download_model: DownloadDataset From bf3d0438a1b48f1df354b04db2079f302266eb20 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Fri, 29 Sep 2023 13:36:27 +0200 Subject: [PATCH 2/2] Generate models --- src/scitacean/_dataset_fields.py | 5 ----- src/scitacean/model.py | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/scitacean/_dataset_fields.py b/src/scitacean/_dataset_fields.py index fa971953..a577e27e 100644 --- a/src/scitacean/_dataset_fields.py +++ b/src/scitacean/_dataset_fields.py @@ -1054,11 +1054,6 @@ def type(self) -> DatasetType: """Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.""" return self._type - @type.setter - def type(self, type: Union[DatasetType, Literal["raw", "derived"]]) -> None: - """Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.""" - self._type = DatasetType(type) - @staticmethod def _prepare_fields_from_download( download_model: DownloadDataset, diff --git a/src/scitacean/model.py b/src/scitacean/model.py index 4f140a45..5a58edae 100644 --- a/src/scitacean/model.py +++ b/src/scitacean/model.py @@ -321,7 +321,6 @@ def download_model_type(cls) -> Type[DownloadAttachment]: class DownloadOrigDatablock(BaseModel): dataFileList: Optional[List[DownloadDataFile]] = None datasetId: Optional[PID] = None - ownerGroup: Optional[str] = None size: Optional[NonNegativeInt] = None id: Optional[str] = pydantic.Field(alias="_id", default=None) accessGroups: Optional[List[str]] = None @@ -329,6 +328,7 @@ class DownloadOrigDatablock(BaseModel): createdAt: Optional[datetime] = None createdBy: Optional[str] = None instrumentGroup: Optional[str] = None + ownerGroup: Optional[str] = None updatedAt: Optional[datetime] = None updatedBy: Optional[str] = None @@ -344,11 +344,11 @@ def upload_model_type(cls) -> Type[UploadOrigDatablock]: class UploadOrigDatablock(BaseModel): dataFileList: List[UploadDataFile] datasetId: PID - ownerGroup: str size: NonNegativeInt accessGroups: Optional[List[str]] = None chkAlg: Optional[str] = None instrumentGroup: Optional[str] = None + ownerGroup: Optional[str] = None @classmethod def download_model_type(cls) -> Type[DownloadOrigDatablock]: