From c9a0c4398747fde6795dda5c26aa12adf6db9eb1 Mon Sep 17 00:00:00 2001 From: nsantacruz Date: Thu, 14 Nov 2024 16:45:14 +0200 Subject: [PATCH] fix(topics): cast queryset to list --- sefaria/model/topic.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sefaria/model/topic.py b/sefaria/model/topic.py index 5d23144241..4f94f27449 100644 --- a/sefaria/model/topic.py +++ b/sefaria/model/topic.py @@ -188,7 +188,7 @@ def load(self, query, proj=None): def _set_derived_attributes(self): self.set_titles(getattr(self, "titles", None)) - self.pools = DjangoTopic.objects.get_pools_by_topic_slug(getattr(self, "slug", None)) + self.pools = list(DjangoTopic.objects.get_pools_by_topic_slug(getattr(self, "slug", None))) if self.__class__ != Topic and not getattr(self, "subclass", False): # in a subclass. set appropriate "subclass" attribute setattr(self, "subclass", self.reverse_subclass_map[self.__class__.__name__]) @@ -241,11 +241,11 @@ def add_pool(self, pool_name: str) -> None: self.pools = self.get_pools() self.pools.append(pool_name) - def remove_pool(self, pool) -> None: - pool = TopicPool.objects.get(name=pool) + def remove_pool(self, pool_name) -> None: + pool = TopicPool.objects.get(name=pool_name) DjangoTopic.objects.get(slug=self.slug).pools.remove(pool) pools = self.get_pools() - pools.remove(pool) + pools.remove(pool_name) def set_titles(self, titles): self.title_group = TitleGroup(titles) @@ -1169,7 +1169,10 @@ def process_topic_delete(topic): for sheet in db.sheets.find({"topics.slug": topic.slug}): sheet["topics"] = [t for t in sheet["topics"] if t["slug"] != topic.slug] db.sheets.save(sheet) - DjangoTopic.objects.get(slug=topic.slug).delete() + try: + DjangoTopic.objects.get(slug=topic.slug).delete() + except DjangoTopic.DoesNotExist: + print('Topic {} does not exist in django'.format(topic.slug)) def process_topic_description_change(topic, **kwargs): """