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