From 80ae20d1ac79ddb5d061271859b510b3d1a4ea41 Mon Sep 17 00:00:00 2001 From: Georg Lehner Date: Wed, 12 Jun 2024 14:58:00 +0200 Subject: [PATCH] Fix: Saving tickets with attachments disabled raises error Exclude code where followups add their attachments to a new ticket. Make helper function _attach_files_to_follow_up() more robust. --- helpdesk/forms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 3124f281..60d363cc 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -327,7 +327,7 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form): return followup def _attach_files_to_follow_up(self, followup): - files = self.cleaned_data['attachment'] + files = self.cleaned_data.get('attachment') if files: files = process_attachments(followup, [files]) return files @@ -419,7 +419,10 @@ class TicketForm(AbstractTicketForm): followup = self._create_follow_up(ticket, title=title, user=user) followup.save() - files = self._attach_files_to_follow_up(followup) + if settings.HELPDESK_ENABLE_ATTACHMENTS: + files = self._attach_files_to_follow_up(followup) + else: + files = None # emit signal when the TicketForm.save is done new_ticket_done.send(sender="TicketForm", ticket=ticket)