diff --git a/apps/export/entries/excel_exporter.py b/apps/export/entries/excel_exporter.py index c5d9fd5154..0f33c53181 100644 --- a/apps/export/entries/excel_exporter.py +++ b/apps/export/entries/excel_exporter.py @@ -275,11 +275,13 @@ def add_entries_from_excel_data_for_static_column( return [entry_excerpt, entry.dropped_excerpt] return entry_excerpt elif exportable == Export.StaticColumn.LEAD_ENTRY_ENTRY_ATTACHMENT_FILE_PREVIEW: - return get_private_file_url( - PrivateFileModuleType.ENTRY_ATTACHMENT, - entry.id, - entry.entry_attachment.file.name - ) + if entry.entry_attachment: + return get_private_file_url( + PrivateFileModuleType.ENTRY_ATTACHMENT, + entry.id, + entry.entry_attachment.file.name + ) + return None def add_entries_from_excel_data(self, rows, data, export_data): export_type = data.get('type') diff --git a/apps/export/tests/snapshots/snap_test_mutations.py b/apps/export/tests/snapshots/snap_test_mutations.py index d7f01eeae0..d3b549e3ab 100644 --- a/apps/export/tests/snapshots/snap_test_mutations.py +++ b/apps/export/tests/snapshots/snap_test_mutations.py @@ -9,5 +9,5 @@ snapshots['TestGenericExportMutationSchema::test_project_stats generic-export-csv'] = '''ID,Title,Created Date,Owners,Start Date,End Date,Last Entry (Date),Organisation (Project owner),Project Stakeholders,Geo Areas,Analysis Framework,Description,Status,Test project (Y/N),Members Count,Sources Count,Entries Count,# of Exports\r 2,Project-1,2021-01-01 00:00:00.123456+00:00,,,,,,,,AF-0,,inactive,N,0,0,0,0\r -1,Project-0,2021-01-01 00:00:00.123456+00:00,,,,2021-01-01 00:00:00.123456+00:00,,,,AF-0,,inactive,N,0,1,10,0\r +1,Project-0,2021-01-01 00:00:00.123456+00:00,,,,2021-01-01 00:00:00.123456+00:00,,,,AF-0,,inactive,N,0,1,20,0\r ''' diff --git a/apps/export/tests/test_mutations.py b/apps/export/tests/test_mutations.py index 29da172544..980fcff907 100644 --- a/apps/export/tests/test_mutations.py +++ b/apps/export/tests/test_mutations.py @@ -17,6 +17,8 @@ from export.tasks import get_export_filename from export.serializers import UserExportCreateGqlSerializer +from entry.models import Entry + class TestExportMutationSchema(GraphQLTestCase): CREATE_EXPORT_QUERY = ''' @@ -798,6 +800,13 @@ def setUp(self): self.project, *_ = ProjectFactory.create_batch(2, analysis_framework=self.af) self.lead = LeadFactory.create(project=self.project) EntryFactory.create_batch(10, lead=self.lead, project=self.project, analysis_framework=self.af) + EntryFactory.create_batch( + 10, + lead=self.lead, + project=self.project, + analysis_framework=self.af, + entry_type=Entry.TagType.ATTACHMENT + ) # User with role self.user = UserFactory.create() # -- Some other data which shouldn't be visible in exports