API: Fix crash when passing an empty seat_category_mapping during event creation

This commit is contained in:
Raphael Michel
2020-01-23 14:27:43 +01:00
parent 934217ee4f
commit 0a9daf0d3a
2 changed files with 6 additions and 2 deletions

View File

@@ -138,8 +138,11 @@ class EventSerializer(I18nAwareModelSerializer):
return value
def validate_seat_category_mapping(self, value):
if value and value['seat_category_mapping'] and (not self.instance or not self.instance.pk):
raise ValidationError('You cannot specify seat category mappings on event creation.')
if not self.instance or not self.instance.pk:
if value and value['seat_category_mapping']:
raise ValidationError('You cannot specify seat category mappings on event creation.')
else:
return {'seat_category_mapping': {}}
item_cache = {i.pk: i for i in self.instance.items.all()}
result = {}
for k, item in value['seat_category_mapping'].items():

View File

@@ -176,6 +176,7 @@ def test_event_create(token_client, organizer, event, meta_prop):
"meta_data": {
meta_prop.name: "Conference"
},
"seat_category_mapping": {},
"timezone": "Europe/Amsterdam"
},
format='json'