From 35d2a73f75f9d186f7b245017148eab07bc8ad39 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 2 Jun 2023 15:52:25 +0200 Subject: [PATCH] Voucher creation: Fix crash in validation (PRETIXEU-8GF) --- src/pretix/control/forms/vouchers.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/pretix/control/forms/vouchers.py b/src/pretix/control/forms/vouchers.py index e82de833ee..56084caef4 100644 --- a/src/pretix/control/forms/vouchers.py +++ b/src/pretix/control/forms/vouchers.py @@ -386,17 +386,18 @@ class VoucherBulkForm(VoucherForm): def clean(self): data = super().clean() - vouchers = self.instance.event.vouchers.annotate( - code_upper=Upper('code') - ).filter(code_upper__in=[c.upper() for c in data['codes']]) - if vouchers.exists(): - raise ValidationError(_('A voucher with one of these codes already exists.')) + if 'codes' in data: + vouchers = self.instance.event.vouchers.annotate( + code_upper=Upper('code') + ).filter(code_upper__in=[c.upper() for c in data['codes']]) + if vouchers.exists(): + raise ValidationError(_('A voucher with one of these codes already exists.')) - codes_seen = set() - for c in data['codes']: - if c in codes_seen: - raise ValidationError(_('The voucher code {code} appears in your list twice.').format(code=c)) - codes_seen.add(c) + codes_seen = set() + for c in data['codes']: + if c in codes_seen: + raise ValidationError(_('The voucher code {code} appears in your list twice.').format(code=c)) + codes_seen.add(c) if data.get('send') and not all([data.get('send_subject'), data.get('send_message'), data.get('send_recipients')]): raise ValidationError(_('If vouchers should be sent by email, subject, message and recipients need to be specified.'))