From a872c8b858e344b3d55fcd982807c5575454a98f Mon Sep 17 00:00:00 2001 From: thenav56 Date: Fri, 20 Oct 2023 09:59:54 +0545 Subject: [PATCH] Return None instead of invalid url --- apps/export/schema.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/apps/export/schema.py b/apps/export/schema.py index 6c2dc0948e..cc66fc8edb 100644 --- a/apps/export/schema.py +++ b/apps/export/schema.py @@ -63,7 +63,7 @@ class Meta: status = graphene.Field(graphene.NonNull(ExportStatusEnum)) export_type = graphene.Field(graphene.NonNull(ExportExportTypeEnum)) file = graphene.Field(FileFieldType) - file_download_url = graphene.String() + file_download_url = graphene.String(required=False) # Filter Data filters = graphene.Field(LeadsFilterDataType) filters_data = graphene.Field(LeadFilterDataType) @@ -79,14 +79,15 @@ def resolve_filters_data(root, info): @staticmethod def resolve_file_download_url(root, info, **kwargs): - return info.context.request.build_absolute_uri( - URLCachedFileField.generate_url( - root.file.name, - parameters={ - 'ResponseContentDisposition': f'filename = "{root.title}.{root.format}"' - } + if root.file and root.file.name: + return info.context.request.build_absolute_uri( + URLCachedFileField.generate_url( + root.file.name, + parameters={ + 'ResponseContentDisposition': f'filename = "{root.title}.{root.format}"' + } + ) ) - ) class UserGenericExportType(DjangoObjectType): @@ -108,7 +109,7 @@ class Meta: filters = GenericScalar(required=False) file = graphene.Field(FileFieldType) - file_download_url = graphene.String() + file_download_url = graphene.String(required=False) @staticmethod def get_custom_queryset(queryset, info, **kwargs): @@ -116,14 +117,15 @@ def get_custom_queryset(queryset, info, **kwargs): @staticmethod def resolve_file_download_url(root, info, **kwargs): - return info.context.request.build_absolute_uri( - URLCachedFileField.generate_url( - root.file.name, - parameters={ - 'ResponseContentDisposition': f'filename = "{root.title}.{root.format}"' - } + if root.file and root.file.name: + return info.context.request.build_absolute_uri( + URLCachedFileField.generate_url( + root.file.name, + parameters={ + 'ResponseContentDisposition': f'filename = "{root.title}.{root.format}"' + } + ) ) - ) class UserExportListType(CustomDjangoListObjectType):