From b219faafaa657385501862e6215c111e957dc52c Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 21 Oct 2019 16:13:03 +0200 Subject: [PATCH] Work around a potential Django bug on MySQL On MySQL, we observe that the preloaded items are missing everywhere except the first time they occur. --- src/pretix/control/views/item.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pretix/control/views/item.py b/src/pretix/control/views/item.py index 470c6c9b76..be404225d6 100644 --- a/src/pretix/control/views/item.py +++ b/src/pretix/control/views/item.py @@ -6,7 +6,7 @@ from django.contrib import messages from django.core.exceptions import PermissionDenied from django.core.files import File from django.db import transaction -from django.db.models import Count, F, Max, Prefetch, Q +from django.db.models import Count, Exists, F, Max, OuterRef, Prefetch, Q from django.forms.models import inlineformset_factory from django.http import ( Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect, @@ -644,7 +644,10 @@ class QuotaList(PaginationMixin, ListView): ).prefetch_related( Prefetch( "items", - queryset=Item.objects.annotate(has_variations=Count('variations')) + queryset=Item.objects.annotate( + has_variations=Exists(ItemVariation.objects.filter(item=OuterRef('pk'))) + ), + to_attr="cached_items" ), "variations", "variations__item"