From 0ff8beffa3a527658737b5348bb1a25f96e65f77 Mon Sep 17 00:00:00 2001 From: Michael Franklin Date: Mon, 18 Sep 2023 11:27:52 +1000 Subject: [PATCH] Revert to the OpenApiGenNoneType for tests --- metamist/parser/generic_parser.py | 2 +- models/base.py | 2 +- models/models/assay.py | 24 ++++++++++++------------ models/models/participant.py | 26 +++++++++++++------------- models/models/sample.py | 28 ++++++++++++++-------------- models/models/sequencing_group.py | 30 +++++++++++++++--------------- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/metamist/parser/generic_parser.py b/metamist/parser/generic_parser.py index 192cdd4fe..a31fea483 100644 --- a/metamist/parser/generic_parser.py +++ b/metamist/parser/generic_parser.py @@ -320,8 +320,8 @@ def __init__( def to_sm(self) -> AssayUpsert: """Convert to SM upsert model""" return AssayUpsert( - type=self.assay_type, id=self.internal_id, + type=self.assay_type, external_ids=self.external_ids, # sample_id=self.s, meta=self.meta, diff --git a/models/base.py b/models/base.py index 133671761..389c38a56 100644 --- a/models/base.py +++ b/models/base.py @@ -2,7 +2,7 @@ # annotate any external objects that must be instantiated with this # type to force openapi generator to allow for Nones (it will actually allow Any) -OpenApiGenNoneType = bytes +OpenApiGenNoneType = bytes | None class SMBase(BaseModel): diff --git a/models/models/assay.py b/models/models/assay.py index dd4118a80..04658ad44 100644 --- a/models/models/assay.py +++ b/models/models/assay.py @@ -1,7 +1,7 @@ import json from typing import Any -from models.base import SMBase +from models.base import OpenApiGenNoneType, SMBase from models.utils.sample_id_format import sample_id_format, sample_id_transform_to_raw @@ -88,11 +88,11 @@ def to_internal(self): class AssayUpsert(SMBase): """Assay upsert model for external use""" - id: int | None = None - type: str | None = None - external_ids: dict[str, str] | None = None - sample_id: str | None = None - meta: dict[str, Any] | None = None + id: int | OpenApiGenNoneType = None + type: str | OpenApiGenNoneType = None + external_ids: dict[str, str] | OpenApiGenNoneType = None + sample_id: str | OpenApiGenNoneType = None + meta: dict[str, Any] | OpenApiGenNoneType = None def to_internal(self): """Convert to internal model""" @@ -101,12 +101,12 @@ def to_internal(self): _sample_id = None if self.sample_id: # but may be provided directly when inserting directly - _sample_id = sample_id_transform_to_raw(self.sample_id) + _sample_id = sample_id_transform_to_raw(self.sample_id) # type: ignore return AssayUpsertInternal( - id=self.id, - type=self.type, - external_ids=self.external_ids, - sample_id=_sample_id, - meta=self.meta, + id=self.id, # type: ignore + type=self.type, # type: ignore + external_ids=self.external_ids, # type: ignore + sample_id=_sample_id, # type: ignore + meta=self.meta, # type: ignore ) diff --git a/models/models/participant.py b/models/models/participant.py index 693a4e198..ab843e343 100644 --- a/models/models/participant.py +++ b/models/models/participant.py @@ -1,7 +1,7 @@ import json from db.python.utils import ProjectId -from models.base import SMBase +from models.base import OpenApiGenNoneType, SMBase from models.models.family import FamilySimple, FamilySimpleInternal from models.models.sample import ( NestedSample, @@ -123,24 +123,24 @@ class NestedParticipant(SMBase): class ParticipantUpsert(SMBase): """External upsert model for participant""" - id: int | None = None - external_id: str | None = None - reported_sex: int | None = None - reported_gender: str | None = None - karyotype: str | None = None - meta: dict | None = None + id: int | OpenApiGenNoneType = None + external_id: str | OpenApiGenNoneType = None + reported_sex: int | OpenApiGenNoneType = None + reported_gender: str | OpenApiGenNoneType = None + karyotype: str | OpenApiGenNoneType = None + meta: dict | OpenApiGenNoneType = None samples: list[SampleUpsert] | None = None def to_internal(self): """Convert to internal model, doesn't really do much""" p = ParticipantUpsertInternal( - id=self.id, - external_id=self.external_id, - reported_sex=self.reported_sex, - reported_gender=self.reported_gender, - karyotype=self.karyotype, - meta=self.meta, + id=self.id, # type: ignore + external_id=self.external_id, # type: ignore + reported_sex=self.reported_sex, # type: ignore + reported_gender=self.reported_gender, # type: ignore + karyotype=self.karyotype, # type: ignore + meta=self.meta, # type: ignore ) if self.samples: diff --git a/models/models/sample.py b/models/models/sample.py index 597f9c8f5..a41c06463 100644 --- a/models/models/sample.py +++ b/models/models/sample.py @@ -1,6 +1,6 @@ import json -from models.base import SMBase +from models.base import OpenApiGenNoneType, SMBase from models.models.assay import Assay, AssayInternal, AssayUpsert, AssayUpsertInternal from models.models.sequencing_group import ( NestedSequencingGroup, @@ -159,13 +159,13 @@ class NestedSample(SMBase): class SampleUpsert(SMBase): """Upsert model for a Sample""" - id: str | None = None - external_id: str | None = None - meta: dict | None = None - project: int | None = None - type: str | None = None - participant_id: int | None = None - active: bool | None = None + id: str | OpenApiGenNoneType = None + external_id: str | OpenApiGenNoneType = None + meta: dict | OpenApiGenNoneType = None + project: int | OpenApiGenNoneType = None + type: str | OpenApiGenNoneType = None + participant_id: int | OpenApiGenNoneType = None + active: bool | OpenApiGenNoneType = None sequencing_groups: list[SequencingGroupUpsert] | None = None non_sequencing_assays: list[AssayUpsert] | None = None @@ -178,12 +178,12 @@ def to_internal(self) -> SampleUpsertInternal: sample_upsert = SampleUpsertInternal( id=_id, - external_id=self.external_id, - meta=self.meta, - project=self.project, - type=self.type, - participant_id=self.participant_id, - active=self.active, + external_id=self.external_id, # type: ignore + meta=self.meta, # type: ignore + project=self.project, # type: ignore + type=self.type, # type: ignore + participant_id=self.participant_id, # type: ignore + active=self.active, # type: ignore ) if self.sequencing_groups: diff --git a/models/models/sequencing_group.py b/models/models/sequencing_group.py index dda1d12e9..1b0bbd3f4 100644 --- a/models/models/sequencing_group.py +++ b/models/models/sequencing_group.py @@ -1,6 +1,6 @@ import json -from models.base import SMBase +from models.base import OpenApiGenNoneType, SMBase from models.models.assay import Assay, AssayInternal, AssayUpsert, AssayUpsertInternal from models.utils.sample_id_format import sample_id_format, sample_id_transform_to_raw from models.utils.sequencing_group_id_format import ( @@ -163,15 +163,15 @@ class SequencingGroupUpsert(SMBase): Upsert model for sequence group """ - id: int | str | None = None - type: str | None = None - technology: str | None = None - platform: str | None = None - meta: dict[str, str] | None = None - sample_id: str | None = None - external_ids: dict[str, str] | None = None + id: int | str | OpenApiGenNoneType = None + type: str | OpenApiGenNoneType = None + technology: str | OpenApiGenNoneType = None + platform: str | OpenApiGenNoneType = None + meta: dict[str, str] | OpenApiGenNoneType = None + sample_id: str | OpenApiGenNoneType = None + external_ids: dict[str, str] | OpenApiGenNoneType = None - assays: list[AssayUpsert] | None = None + assays: list[AssayUpsert] | OpenApiGenNoneType = None def to_internal(self) -> SequencingGroupUpsertInternal: """ @@ -187,15 +187,15 @@ def to_internal(self) -> SequencingGroupUpsertInternal: sg_internal = SequencingGroupUpsertInternal( id=_id, - type=self.type, - technology=self.technology, - platform=self.platform.lower() if self.platform else None, - meta=self.meta, + type=self.type, # type: ignore + technology=self.technology, # type: ignore + platform=self.platform.lower() if self.platform else None, # type: ignore + meta=self.meta, # type: ignore sample_id=_sample_id, - external_ids=self.external_ids or {}, + external_ids=self.external_ids or {}, # type: ignore ) if self.assays is not None: - sg_internal.assays = [a.to_internal() for a in self.assays] + sg_internal.assays = [a.to_internal() for a in self.assays] # type: ignore return sg_internal