From 8d501e18e6aa0799090a279f0f00ec65738e0364 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Fri, 22 Nov 2024 15:05:52 +0100
Subject: [PATCH] Use prefetched amends and prevent resolving by optimizer

This would problematic due to django-polymorphic.
---
 aleksis/apps/alsijil/models.py               | 1 +
 aleksis/apps/alsijil/schema/documentation.py | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py
index e628fecb5..d681e04ad 100644
--- a/aleksis/apps/alsijil/models.py
+++ b/aleksis/apps/alsijil/models.py
@@ -182,6 +182,7 @@ class Documentation(CalendarEvent):
                     )
                 ):
                     continue
+                doc._amends_prefetched = event_reference_obj
                 docs.append(doc)
             elif not absences_exist:
                 if event_reference_obj.amends:
diff --git a/aleksis/apps/alsijil/schema/documentation.py b/aleksis/apps/alsijil/schema/documentation.py
index b833de336..fe45b7fb2 100644
--- a/aleksis/apps/alsijil/schema/documentation.py
+++ b/aleksis/apps/alsijil/schema/documentation.py
@@ -32,7 +32,6 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
         fields = (
             "id",
             "course",
-            "amends",
             "subject",
             "topic",
             "homework",
@@ -61,6 +60,12 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
 
     old_id = graphene.ID(required=False)
 
+    @staticmethod
+    def resolve_amends(root: Documentation, info, **kwargs):
+        if hasattr(root, "_amends_prefetched"):
+            return root._amends_prefetched
+        return root.amends
+
     @staticmethod
     def resolve_teachers(root: Documentation, info, **kwargs):
         if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"):
-- 
GitLab