From 9fcc99c6f24a73bcae977b284a0c7a0239c3e029 Mon Sep 17 00:00:00 2001 From: Xander Vertegaal Date: Mon, 9 Dec 2024 20:32:26 +0100 Subject: [PATCH] Fix spurious agent duplication bug --- backend/event/types/EpisodeType.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/event/types/EpisodeType.py b/backend/event/types/EpisodeType.py index ecfd933f..03078fae 100644 --- a/backend/event/types/EpisodeType.py +++ b/backend/event/types/EpisodeType.py @@ -5,10 +5,14 @@ from event.models import Episode, EpisodeCategory from event.types.EpisodeCategoryType import EpisodeCategoryType +from person.models import AgentDescription class EpisodeType(EntityDescriptionType, DjangoObjectType): categories = List(NonNull(EpisodeCategoryType), required=True) + agents = List( + NonNull("person.types.AgentDescriptionType.AgentDescriptionType"), required=True + ) class Meta: model = Episode @@ -17,7 +21,6 @@ class Meta: "summary", "categories", "designators", - "agents", "gifts", "letters", "spaces", @@ -32,6 +35,14 @@ def get_queryset( ) -> QuerySet[Episode]: return queryset.all() + @staticmethod + def resolve_agents( + parent: Episode, info: ResolveInfo + ) -> QuerySet[AgentDescription]: + # Without distinct(), this returns one agent for every HistoricalPerson linked + # to that agent, for some reason. + return parent.agents.distinct() + @staticmethod def resolve_categories( parent: Episode, info: ResolveInfo