From 5a6970cb5add0ac22a7b85cbe4c38e72b81d94da Mon Sep 17 00:00:00 2001 From: Stefan Wehrmeyer Date: Tue, 14 Jan 2025 15:29:09 +0100 Subject: [PATCH] Fix queryset update with annotated order columns --- fragdenstaat_de/fds_donation/admin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fragdenstaat_de/fds_donation/admin.py b/fragdenstaat_de/fds_donation/admin.py index 87bb7093..1c89f57d 100644 --- a/fragdenstaat_de/fds_donation/admin.py +++ b/fragdenstaat_de/fds_donation/admin.py @@ -297,7 +297,8 @@ def send_donor_optin_email(self, request, queryset): send_donor_optin_email.short_description = _("Send opt-in mail") def clear_duplicates(self, request, queryset): - queryset.update(duplicate=None) + # Clear order of queryset to avoid ordering on non-existing annotation columns + queryset.order_by().update(duplicate=None) self.message_user(request, _("Duplicate flags cleared.")) clear_duplicates.short_description = _("Clear duplicate flag on donors") @@ -340,13 +341,15 @@ def detect_duplicates(self, request, queryset): @admin.action(description=_("Mark invalid addresses")) def mark_invalid_addresses(self, request, queryset): - queryset.filter( + qs = queryset.filter( Q(postcode="") | Q(address="") | Q(city="") | Q(last_name="") | ~(Q(postcode__regex=r"^\d{5}$") | ~Q(country="DE")) - ).update(invalid=True) + ) + # Clear order of queryset to avoid ordering on non-existing annotation columns + qs.order_by().update(invalid=True) def merge_donors(self, request, queryset): """