diff --git a/server/api/graphene_wagtail.py b/server/api/graphene_wagtail.py index 2729788e..4f335910 100644 --- a/server/api/graphene_wagtail.py +++ b/server/api/graphene_wagtail.py @@ -25,17 +25,21 @@ class GenericStreamFieldType(Scalar): return list(augment_fields(raw_data)) def get_document_json(document_id): - document = CustomDocument.objects.get(id=document_id) - value = { - 'value': document_id, - 'id': document.id, - 'file_name': document.filename, - 'file_extension': document.file_extension, - 'url': document.url, - 'title': document.title, - 'display_text': document.display_text - } - return value + try: + document = CustomDocument.objects.get(id=document_id) + value = { + 'value': document_id, + 'id': document.id, + 'file_name': document.filename, + 'file_extension': document.file_extension, + 'url': document.url, + 'title': document.title, + 'display_text': document.display_text + } + return value + except CustomDocument.DoesNotExist: + logger.error('CustomDocument {} does not exist'.format(document_id)) + return None def augment_fields(raw_data): @@ -102,18 +106,17 @@ def augment_fields(raw_data): data['value'] = augment_fields(item_data) if _type == 'cms_document_block': - try: - _value = data['value'] - value = get_document_json(_value) + _value = data['value'] + value = get_document_json(_value) + if value is not None: data['value'] = value - except CustomDocument.DoesNotExist: - logger.error('CustomDocument {} does not exist'.format(_value)) if _type == 'solution' or _type == 'instruction': _value = data['value'] document_id = _value.get('document') if document_id is not None: document = get_document_json(document_id) - _value['document'] = document + if document is not None: + _value['document'] = document data['value'] = _value