From 0f37e0ad42262966a01271d5adb9a5198f357ce7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 5 Jan 2022 15:55:12 -0800 Subject: [PATCH] Don't try to clear caches for nonexistant authors --- bookwyrm/models/author.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index a4d8f9f16..5edac57d5 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -39,12 +39,12 @@ class Author(BookDataModel): def save(self, *args, **kwargs): """clear related template caches""" # clear template caches - cache_keys = [ - make_template_fragment_key("titleby", [book]) - for book in self.book_set.values_list("id", flat=True) - ] - cache.delete_many(cache_keys) - + if self.id: + cache_keys = [ + make_template_fragment_key("titleby", [book]) + for book in self.book_set.values_list("id", flat=True) + ] + cache.delete_many(cache_keys) return super().save(*args, **kwargs) @property