From d0b91698d3dca16d6c54a2cbe9822a6715425320 Mon Sep 17 00:00:00 2001 From: Keeva Date: Mon, 28 Sep 2026 13:47:58 +1000 Subject: [PATCH 1/4] adding project_id and sample_id to broker claimed entity schema --- app/schemas/broker_contract.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/schemas/broker_contract.py b/app/schemas/broker_contract.py index 066f8c6..9c77af1 100644 --- a/app/schemas/broker_contract.py +++ b/app/schemas/broker_contract.py @@ -36,6 +36,8 @@ class BrokerClaimEntity(BaseModel): id: UUID taxon_id: str scientific_name: Optional[str] = None + project_id: Optional[UUID] = None + sample_id: Optional[UUID] = None payload: Optional[Dict[str, Any]] = None prerequisites: Optional[BrokerPrerequisites] = None files: Optional[List[BrokerFileMetadata]] = None From cc9f526930f163e035b9d0ef00e2f17dbfdedda0 Mon Sep 17 00:00:00 2001 From: Keeva Date: Mon, 28 Sep 2026 13:49:16 +1000 Subject: [PATCH 2/4] looking up experiments' related project and sample ids to pass to the broker --- app/api/v1/endpoints/broker.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/api/v1/endpoints/broker.py b/app/api/v1/endpoints/broker.py index f2ffb61..49e4a66 100644 --- a/app/api/v1/endpoints/broker.py +++ b/app/api/v1/endpoints/broker.py @@ -181,6 +181,20 @@ def _lookup_scientific_name(db: Session, *, taxon_id: str | int) -> Optional[str return db.query(Organism.scientific_name).filter(Organism.taxon_id == tax_id_int).scalar() +def _lookup_project_id(db: Session, *, entity_id: UUID) -> Optional[UUID]: + project_id = (db.query(Experiment.project_id).filter(Experiment.id == entity_id).scalar()) + if not project_id: + return None + return project_id + + +def _lookup_sample_id(db: Session, *, entity_id: UUID) -> Optional[UUID|None]: + sample_id = (db.query(Experiment.sample_id).filter(Experiment.id == entity_id).scalar()) + if not sample_id: + return None + return sample_id + + def _create_new_draft_submission_after_rejection( db: Session, *, @@ -384,6 +398,13 @@ def _build_contract_entity( files = _extract_run_files(prepared_payload) if entity_type == BrokerEntityType.RUN else None scientific_name = _lookup_scientific_name(db, taxon_id=taxon_id) + if entity_type == BrokerEntityType.EXPERIMENT: + project_id = _lookup_project_id(db, entity_id=entity_id) + sample_id = _lookup_sample_id(db, entity_id=entity_id) + else: + project_id = None + sample_id = None + if entity_type in (BrokerEntityType.EXPERIMENT, BrokerEntityType.SAMPLE): title = _derive_claim_title( db, entity_type=entity_type, entity_id=entity_id, taxon_id=taxon_id @@ -396,6 +417,8 @@ def _build_contract_entity( id=entity_id, taxon_id=str(taxon_id), scientific_name=scientific_name, + project_id=project_id, + sample_id=sample_id, payload=prepared_payload or None, prerequisites=prerequisites if _prerequisites_to_dict(prerequisites) else None, files=files, From 31b20d4566c75204ece9e28eb777b3963479359c Mon Sep 17 00:00:00 2001 From: Keeva Date: Thu, 1 Oct 2026 08:20:46 +1000 Subject: [PATCH 3/4] fix: returning SAMEA accession in entity prerequisites for broker endpoints --- app/api/v1/endpoints/broker.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/api/v1/endpoints/broker.py b/app/api/v1/endpoints/broker.py index 49e4a66..77a50bf 100644 --- a/app/api/v1/endpoints/broker.py +++ b/app/api/v1/endpoints/broker.py @@ -317,15 +317,26 @@ def _get_accession_for_entity( """Lookup accession from accession_registry for a given entity.""" if not entity_id: return None - return ( - db.query(AccessionRegistry.accession) - .filter( - AccessionRegistry.entity_type == entity_type, - AccessionRegistry.entity_id == entity_id, - AccessionRegistry.authority == authority, + if entity_type == "sample": + return ( + db.query(AccessionRegistry.secondary_accession) + .filter( + AccessionRegistry.entity_type == entity_type, + AccessionRegistry.entity_id == entity_id, + AccessionRegistry.authority == authority, + ) + .scalar() + ) + else: + return ( + db.query(AccessionRegistry.accession) + .filter( + AccessionRegistry.entity_type == entity_type, + AccessionRegistry.entity_id == entity_id, + AccessionRegistry.authority == authority, + ) + .scalar() ) - .scalar() - ) def _extract_broker_prerequisites( From 8ffc96a716f10447a51ade0dc5a1cfde481cf88a Mon Sep 17 00:00:00 2001 From: Keeva Date: Thu, 1 Oct 2026 13:09:32 +1000 Subject: [PATCH 4/4] style: linting --- app/api/v1/endpoints/broker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/api/v1/endpoints/broker.py b/app/api/v1/endpoints/broker.py index 77a50bf..754fc7d 100644 --- a/app/api/v1/endpoints/broker.py +++ b/app/api/v1/endpoints/broker.py @@ -182,14 +182,14 @@ def _lookup_scientific_name(db: Session, *, taxon_id: str | int) -> Optional[str def _lookup_project_id(db: Session, *, entity_id: UUID) -> Optional[UUID]: - project_id = (db.query(Experiment.project_id).filter(Experiment.id == entity_id).scalar()) + project_id = db.query(Experiment.project_id).filter(Experiment.id == entity_id).scalar() if not project_id: return None return project_id -def _lookup_sample_id(db: Session, *, entity_id: UUID) -> Optional[UUID|None]: - sample_id = (db.query(Experiment.sample_id).filter(Experiment.id == entity_id).scalar()) +def _lookup_sample_id(db: Session, *, entity_id: UUID) -> Optional[UUID]: + sample_id = db.query(Experiment.sample_id).filter(Experiment.id == entity_id).scalar() if not sample_id: return None return sample_id