From 84cc71e8bc46e79713a2024054a2a53116947864 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Wed, 4 Dec 2024 19:25:09 +0100 Subject: [PATCH] Fix error handling in sponsor signup form Fix a crash, ensure error details are sent to the admins, and make sure a left-over sponsor record isn't in the database in the event of an error late in the process. --- postgresqleu/confsponsor/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/postgresqleu/confsponsor/views.py b/postgresqleu/confsponsor/views.py index d802a444..c19cfa6b 100644 --- a/postgresqleu/confsponsor/views.py +++ b/postgresqleu/confsponsor/views.py @@ -515,7 +515,7 @@ def sponsor_signup(request, confurlname, levelurlname): mailstr += "No invoice has been generated as for this level\na signed contract is required first. The sponsor\nhas been sent a contract for digital signing." if error: - form.add_error("Failed to send digital contract.") + form.add_error(None, "Failed to send digital contract") else: sponsor.contract = DigisignDocument( provider=conference.contractprovider, @@ -525,7 +525,13 @@ def sponsor_signup(request, confurlname, levelurlname): sponsor.contract.save() sponsor.save(update_fields=['contract', ]) - if not error: + if error: + send_conference_sponsor_notification( + conference, + "Failed to send digital contract", + "Failed to send digital contract to {}: {}".format(sponsor.name, error), + ) + else: send_conference_sponsor_notification( conference, "Sponsor %s signed up for %s" % (sponsor.name, conference), @@ -535,6 +541,8 @@ def sponsor_signup(request, confurlname, levelurlname): # Redirect back to edit the actual sponsorship entry return HttpResponseRedirect('/events/sponsor/%s/' % sponsor.id) # Else on error we fall through and re-render the form with the error + # Also remove the sponsor entry that was created + sponsor.delete() else: form = SponsorSignupForm(conference) -- 2.39.5