|
14 | 14 | Q, |
15 | 15 | UUIDField, |
16 | 16 | Value, |
| 17 | + When, |
| 18 | + Case, |
17 | 19 | ) |
18 | 20 | from django.db.models.functions import Coalesce |
19 | 21 | from django.utils import timezone |
@@ -83,7 +85,15 @@ def get(self, request, slug, project_id): |
83 | 85 | .filter(workspace__slug=self.kwargs.get("slug")) |
84 | 86 | .select_related("workspace", "project", "state", "parent") |
85 | 87 | .prefetch_related("assignees", "labels", "issue_module__module") |
86 | | - .annotate(cycle_id=F("issue_cycle__cycle_id")) |
| 88 | + .annotate( |
| 89 | + cycle_id=Case( |
| 90 | + When( |
| 91 | + issue_cycle__cycle__deleted_at__isnull=True, |
| 92 | + then=F("issue_cycle__cycle_id"), |
| 93 | + ), |
| 94 | + default=None, |
| 95 | + ) |
| 96 | + ) |
87 | 97 | .annotate( |
88 | 98 | link_count=IssueLink.objects.filter(issue=OuterRef("id")) |
89 | 99 | .order_by() |
@@ -207,7 +217,15 @@ def get_queryset(self): |
207 | 217 | .filter(workspace__slug=self.kwargs.get("slug")) |
208 | 218 | .select_related("workspace", "project", "state", "parent") |
209 | 219 | .prefetch_related("assignees", "labels", "issue_module__module") |
210 | | - .annotate(cycle_id=F("issue_cycle__cycle_id")) |
| 220 | + .annotate( |
| 221 | + cycle_id=Case( |
| 222 | + When( |
| 223 | + issue_cycle__cycle__deleted_at__isnull=True, |
| 224 | + then=F("issue_cycle__cycle_id"), |
| 225 | + ), |
| 226 | + default=None, |
| 227 | + ) |
| 228 | + ) |
211 | 229 | .annotate( |
212 | 230 | link_count=IssueLink.objects.filter(issue=OuterRef("id")) |
213 | 231 | .order_by() |
@@ -757,7 +775,15 @@ def get_queryset(self): |
757 | 775 | "workspace", "project", "state", "parent" |
758 | 776 | ) |
759 | 777 | .prefetch_related("assignees", "labels", "issue_module__module") |
760 | | - .annotate(cycle_id=F("issue_cycle__cycle_id")) |
| 778 | + .annotate( |
| 779 | + cycle_id=Case( |
| 780 | + When( |
| 781 | + issue_cycle__cycle__deleted_at__isnull=True, |
| 782 | + then=F("issue_cycle__cycle_id"), |
| 783 | + ), |
| 784 | + default=None, |
| 785 | + ) |
| 786 | + ) |
761 | 787 | .annotate( |
762 | 788 | link_count=IssueLink.objects.filter(issue=OuterRef("id")) |
763 | 789 | .order_by() |
|
0 commit comments