From 88b0274e5c9f3eb38e9d64295a27dfcbefd785ab Mon Sep 17 00:00:00 2001 From: Phin Wolkwitz Date: Wed, 5 Aug 2026 14:05:31 +0200 Subject: [PATCH] Improve QuerySet order --- src/pretix/plugins/sendmail/tasks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pretix/plugins/sendmail/tasks.py b/src/pretix/plugins/sendmail/tasks.py index fa537b421c..f73c5ff4da 100644 --- a/src/pretix/plugins/sendmail/tasks.py +++ b/src/pretix/plugins/sendmail/tasks.py @@ -33,7 +33,7 @@ # License for the specific language governing permissions and limitations under the License. from datetime import datetime -from django.db.models import Exists, OuterRef, Q +from django.db.models import Exists, OuterRef, Q, F from i18nfield.strings import LazyI18nString from pretix.base.email import get_email_context @@ -86,7 +86,8 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict, list_id__in=checkin_lists or [] ) ), - ).order_by('pk').prefetch_related('addons', 'subevent'): + ).order_by(F("addon_to_id").asc(nulls_first=True)).prefetch_related('addons', 'subevent'): + # ordered QuerySet to make sure we always handle parent order positions before add-ons is_addon = p.addon_to_id is not None