Skip to content

Commit

Permalink
add human-readable error for misconfigured PDO
Browse files Browse the repository at this point in the history
  • Loading branch information
hanars committed Nov 14, 2024
1 parent 60f720e commit 32bc50e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions seqr/views/utils/airtable_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.exceptions import PermissionDenied

from seqr.utils.logging_utils import SeqrLogger
from seqr.utils.middleware import ErrorsWarningsException
from seqr.views.utils.terra_api_utils import is_cloud_authenticated

from settings import AIRTABLE_API_KEY, AIRTABLE_URL, BASE_URL
Expand Down Expand Up @@ -167,11 +168,14 @@ def get_samples_for_matched_pdos(self, pdo_statuses, pdo_fields=None, project_gu
# Filter for array contains value instead of exact match
filter_query_template="SEARCH('{value}',ARRAYJOIN({key},';'))",
)

invalid_pdo_samples = []
for sample in sample_records.values():
sample_id = sample.get('SeqrCollaboratorSampleID') or sample['CollaboratorSampleID']
project_guids = [
re.match(f'{BASE_URL}project/([^/]+)/project_page', url).group(1) for url in sample['SeqrProject']
]
if len(project_guids) > 1 and len(project_guids) < len(sample['PDOStatus']):
invalid_pdo_samples.append(sample_id)
pdos = [{
'project_guid': project_guids[i] if len(project_guids) > 1 else project_guids[0],
**{field: sample[field][i] for field in pdo_fields}
Expand All @@ -180,7 +184,13 @@ def get_samples_for_matched_pdos(self, pdo_statuses, pdo_fields=None, project_gu
pdos = [pdo for pdo in pdos if pdo['project_guid'] == project_guid]
sample.update({
'pdos': pdos,
'sample_id': sample.get('SeqrCollaboratorSampleID') or sample['CollaboratorSampleID'],
'sample_id': sample_id,
})

if invalid_pdo_samples:
samples = ', '.join(sorted(invalid_pdo_samples))
raise ErrorsWarningsException([
f'The following samples are associated with misconfigured PDOs in Airtable: {samples}'
])

return {record_id: sample for record_id, sample in sample_records.items() if sample['pdos']}

0 comments on commit 32bc50e

Please sign in to comment.