Skip to content

Commit 128b4c0

Browse files
authored
Merge pull request #5105 from broadinstitute/clear-parental-data-update
handle clearing parental data
2 parents d21c2b3 + 20ff0be commit 128b4c0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

seqr/views/apis/individual_api_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ def test_edit_individuals(self, mock_pm_group):
245245
self.assertEqual(response_json['individualsByGuid'][ID_UPDATE_GUID]['individualId'], UPDATED_ID)
246246
self.assertEqual(response_json['individualsByGuid'][ID_UPDATE_GUID]['maternalId'], 'NA19679')
247247

248+
response = self.client.post(edit_individuals_url, content_type='application/json', data=json.dumps({
249+
'individuals': [{
250+
'individualGuid': INDIVIDUAL_GUID,
251+
'familyId': '1',
252+
'individualId': 'NA19675_1',
253+
'paternalId': '',
254+
}]
255+
}))
256+
self.assertEqual(response.status_code, 200)
257+
response_json = response.json()
258+
self.assertSetEqual({INDIVIDUAL_GUID}, set(response_json['individualsByGuid']))
259+
self.assertIsNone(response_json['individualsByGuid'][INDIVIDUAL_GUID]['paternalId'])
260+
self.assertEqual(response_json['individualsByGuid'][INDIVIDUAL_GUID]['maternalId'], 'NA19679')
261+
248262
# Test PM permission
249263
pm_required_edit_individuals_url = reverse(edit_individuals_handler, args=[PM_REQUIRED_PROJECT_GUID])
250264
response = self.client.post(pm_required_edit_individuals_url, content_type='application/json', data=json.dumps({

seqr/views/utils/individual_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _update_from_record(record, user, families_by_id, individual_lookup, updated
143143
'mother': record.pop('mother', None),
144144
'father': record.pop('father', None),
145145
})
146-
elif record.get('maternalId') or record.get('paternalId'):
146+
elif record.get('maternalId') is not None or record.get('paternalId') is not None:
147147
parent_updates.append({
148148
'individual': individual,
149149
'maternalId': record.pop('maternalId', None),

seqr/views/utils/json_to_orm_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ def update_individual_parents(individual, json, user):
5555

5656
def _parse_parent_field(update_json, all_json, individual, parent_key, parent_id_key):
5757
updated_parent = all_json.get(parent_id_key) if parent_id_key else all_json.get(parent_key)
58+
if updated_parent is None:
59+
return
5860
parent = getattr(individual, parent_key, None)
5961
if parent_id_key:
6062
parent = parent.individual_id if parent else None
61-
if updated_parent != parent:
63+
if parent and not updated_parent:
64+
update_json[parent_key] = None
65+
elif updated_parent != parent:
6266
if parent_id_key:
6367
updated_parent = Individual.objects.get(individual_id=updated_parent, family=individual.family) if updated_parent else None
6468
update_json[parent_key] = updated_parent

0 commit comments

Comments
 (0)