From e3e9e0dd96b6777896522be48dfb36b966c99fac Mon Sep 17 00:00:00 2001 From: Milos Despotovic Date: Tue, 31 Dec 2024 11:25:08 -0800 Subject: [PATCH] Handle documents with no attributes present --- .../request_api/services/recordservice.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/request-management-api/request_api/services/recordservice.py b/request-management-api/request_api/services/recordservice.py index e84b02d3a..40e1be047 100644 --- a/request-management-api/request_api/services/recordservice.py +++ b/request-management-api/request_api/services/recordservice.py @@ -83,6 +83,14 @@ def updatepersonalattributes(self, requestid, ministryrequestid, requestdata, us record['attributes'] = json.loads(record['attributes']) for attribute in requestdata['newpersonalattributes']: if (requestdata['newpersonalattributes'][attribute] is not None and len(requestdata['newpersonalattributes'][attribute]) > 0): + if 'attributes' in record: + if 'personalattributes' in record['attributes']: + record['attributes']['personalattributes'][attribute] = requestdata['newpersonalattributes'][attribute] + else: + record['attributes']['personalattributes'] = {} + else: + record['attributes'] = {} + record['attributes']['personalattributes'] = {} record['attributes']['personalattributes'][attribute] = requestdata['newpersonalattributes'][attribute] # divisions = divisions + [div for div in record['attributes']['divisions'] if div not in divisions] record.update({'updated_at': datetime.now(), 'updatedby': userid})