Skip to content

Commit

Permalink
fix: prevent unwanted phenopacket dataset update in ingestion
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rocheleau committed Dec 4, 2023
2 parents 4e934a0 + 0275973 commit 9fef2c1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions chord_metadata_service/chord/ingest/phenopackets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import uuid
from humps import decamelize

from dateutil.parser import isoparse
Expand Down Expand Up @@ -320,7 +319,12 @@ def ingest_phenopacket(phenopacket_data: dict[str, Any],
if phenopacket_data.get("files", []):
logger.warning("Found files in phenopacket.files are not ingested by Katsu.")

new_phenopacket_id = phenopacket_data.get("id", str(uuid.uuid4()))
# Abort the ingestion if the phenopacket's ID exists in the DB
phenopacket_id = phenopacket_data.get("id")
if pm.Phenopacket.objects.filter(id=phenopacket_id).exists():
error_msg = f"Cannot ingest Phenopacket with ID {phenopacket_id}, ID already exists in the database."
logger.error(error_msg)
raise IngestError(error_msg)

subject = phenopacket_data.get("subject")

Expand Down Expand Up @@ -377,25 +381,25 @@ def ingest_phenopacket(phenopacket_data: dict[str, Any],
meta_data_obj.resources.set(resources_db)

# Create the phenopacket object...
new_phenopacket = pm.Phenopacket(
id=new_phenopacket_id,
phenopacket = pm.Phenopacket(
id=phenopacket_id,
subject=subject_obj,
measurements=measurements,
medical_actions=medical_actions,
meta_data=meta_data_obj,
dataset=Dataset.objects.get(identifier=dataset_id),
)

# ... save it to the database...
new_phenopacket.save()
# ... save it to the database...
phenopacket.save()

# ... and attach all the other objects to it.
new_phenopacket.phenotypic_features.set(phenotypic_features_db)
new_phenopacket.interpretations.set(interpretations_db)
new_phenopacket.biosamples.set(biosamples_db)
new_phenopacket.diseases.set(diseases_db)
phenopacket.phenotypic_features.set(phenotypic_features_db)
phenopacket.interpretations.set(interpretations_db)
phenopacket.biosamples.set(biosamples_db)
phenopacket.diseases.set(diseases_db)

return new_phenopacket
return phenopacket


def ingest_phenopacket_workflow(json_data, dataset_id) -> Union[list[pm.Phenopacket], pm.Phenopacket]:
Expand Down

0 comments on commit 9fef2c1

Please sign in to comment.