Skip to content

Commit

Permalink
Merge pull request #1491 from microbiomedata/fix-allow-string-package…
Browse files Browse the repository at this point in the history
…-name-on-create

Allow creating a submission with string or list of strings for `packageName`
  • Loading branch information
pkalita-lbl authored Dec 11, 2024
2 parents e150223 + 5e11b51 commit 48a99fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions nmdc_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,14 @@ async def submit_metadata(
db: Session = Depends(get_db),
user: models.User = Depends(get_current_user),
):
# Old versions of the Field Notes app will continue to send a string for packageName
# for a little while. This code is to ease that transition and can be removed in the future.
if isinstance(body.metadata_submission.packageName, str):
if body.metadata_submission.packageName:
body.metadata_submission.packageName = [body.metadata_submission.packageName]
else:
body.metadata_submission.packageName = []

submission = SubmissionMetadata(
**body.dict(),
author_orcid=user.orcid,
Expand Down
12 changes: 8 additions & 4 deletions nmdc_server/schemas_submission.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union
from uuid import UUID

from pydantic import BaseModel, ConfigDict, ValidationInfo, field_validator
Expand Down Expand Up @@ -74,8 +74,8 @@ class ContextForm(BaseModel):
unknownDoi: Optional[bool] = None


class MetadataSubmissionRecord(BaseModel):
packageName: List[str]
class MetadataSubmissionRecordCreate(BaseModel):
packageName: Union[str, List[str]]
contextForm: ContextForm
addressForm: AddressForm
templates: List[str]
Expand All @@ -84,6 +84,10 @@ class MetadataSubmissionRecord(BaseModel):
sampleData: Dict[str, List[Any]]


class MetadataSubmissionRecord(MetadataSubmissionRecordCreate):
packageName: List[str]


class PartialMetadataSubmissionRecord(BaseModel):
packageName: Optional[List[str]] = None
contextForm: Optional[ContextForm] = None
Expand All @@ -95,7 +99,7 @@ class PartialMetadataSubmissionRecord(BaseModel):


class SubmissionMetadataSchemaCreate(BaseModel):
metadata_submission: MetadataSubmissionRecord
metadata_submission: MetadataSubmissionRecordCreate
status: Optional[str] = None
source_client: Optional[str] = None

Expand Down

0 comments on commit 48a99fe

Please sign in to comment.