Skip to content

Commit

Permalink
fix(topics): cast queryset to list
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Nov 14, 2024
1 parent af9f31d commit c9a0c43
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sefaria/model/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit c9a0c43

Please sign in to comment.