API: Fix crash with deletion of cart positions with add-ons

This commit is contained in:
Raphael Michel
2022-10-25 12:08:58 +02:00
parent b99d21df69
commit 4983073172
2 changed files with 11 additions and 0 deletions

View File

@@ -92,6 +92,11 @@ class CartPositionViewSet(CreateModelMixin, DestroyModelMixin, viewsets.ReadOnly
def perform_create(self, serializer):
raise NotImplementedError()
@transaction.atomic()
def perform_destroy(self, instance):
instance.addons.all().delete()
instance.delete()
def _require_locking(self, quota_diff, voucher_use_diff, seat_diff):
if voucher_use_diff or seat_diff:
# If any vouchers or seats are used, we lock to make sure we don't redeem them to often

View File

@@ -167,6 +167,12 @@ def test_cp_delete(token_client, organizer, event, item, taxrule, question):
datetime=datetime.datetime(2018, 6, 11, 10, 0, 0, 0, tzinfo=UTC),
expires=datetime.datetime(2018, 6, 11, 10, 0, 0, 0, tzinfo=UTC)
)
CartPosition.objects.create(
event=event, cart_id="aaa@api", item=item, addon_to=cr,
price=23, attendee_name_parts={'full_name': 'Peter'},
datetime=datetime.datetime(2018, 6, 11, 10, 0, 0, 0, tzinfo=UTC),
expires=datetime.datetime(2018, 6, 11, 10, 0, 0, 0, tzinfo=UTC)
)
res = dict(TEST_CARTPOSITION_RES)
res["id"] = cr.pk
res["item"] = item.pk