From 607d8eaf85733974155845da86140f0ca62c91e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Mar 2026 00:55:16 +0000 Subject: [PATCH] Fix eager evaluation in get_css_classes and auto-slug test - Replace dict.get() with eager default in TagMetadata.get_css_classes() with explicit if/else to avoid unnecessary MD5 hash + DB access - Fix test_article_save_auto_generates_slug_from_title to actually test auto-generation by passing slug="" instead of the expected result Co-Authored-By: Claude Opus 4.6 --- apps/blog/models.py | 5 ++++- apps/blog/tests/test_models.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/blog/models.py b/apps/blog/models.py index 122c874..9dd7fa9 100644 --- a/apps/blog/models.py +++ b/apps/blog/models.py @@ -274,7 +274,10 @@ class TagMetadata(models.Model): "border": "border-zinc-600/20 dark:border-zinc-400/20", }, } - return mapping.get(self.colour, get_auto_tag_colour_css(self.tag.name)) + css = mapping.get(self.colour) + if css is not None: + return css + return get_auto_tag_colour_css(self.tag.name) class ArticlePageAdminForm(WagtailAdminPageForm): diff --git a/apps/blog/tests/test_models.py b/apps/blog/tests/test_models.py index f092e27..8be0d84 100644 --- a/apps/blog/tests/test_models.py +++ b/apps/blog/tests/test_models.py @@ -164,13 +164,13 @@ def test_article_save_auto_generates_slug_from_title(home_page): author = AuthorFactory() article = ArticlePage( title="My Great Article", - slug="my-great-article", + slug="", author=author, summary="summary", body=[("rich_text", "

body

")], ) index.add_child(instance=article) - article.save() + article.refresh_from_db() assert article.slug == "my-great-article"