From e46b33544d49db433f70bcfa8512a419aa0aaf13 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 11 Jul 2018 14:57:31 +0200 Subject: [PATCH] Fix race condition in formset validation --- src/pretix/control/forms/item.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pretix/control/forms/item.py b/src/pretix/control/forms/item.py index b30b8b040b..e6487f54e4 100644 --- a/src/pretix/control/forms/item.py +++ b/src/pretix/control/forms/item.py @@ -404,19 +404,20 @@ class ItemAddOnsFormSet(I18nFormSet): def clean(self): super().clean() - categories = set() + categories = set(self.queryset.values_list('addon_category_id', flat=True)) for i in range(0, self.total_form_count()): form = self.forms[i] if self.can_delete: if self._should_delete_form(form): # This form is going to be deleted so any of its errors # should not cause the entire formset to be invalid. + categories.remove(form.cleaned_data['addon_category'].pk) continue - if form.cleaned_data['addon_category'] in categories: + if form.cleaned_data['addon_category'].pk in categories: raise ValidationError(_('You added the same add-on category twice')) - categories.add(form.cleaned_data['addon_category']) + categories.add(form.cleaned_data['addon_category'].pk) @property def empty_form(self):