diff --git a/pelican/contents.py b/pelican/contents.py index 9254701b..ee357161 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -170,13 +170,16 @@ class Content: return self.source_path or repr(self) def _has_valid_mandatory_properties(self) -> bool: - """Test mandatory properties are set.""" + """Test mandatory properties are set and not empty.""" for prop in self.mandatory_properties: - if not hasattr(self, prop) or getattr(self, prop) in (None, ""): + if not hasattr(self, prop): logger.error( - "Skipping %s: could not find information about '%s'", self, prop + "Skipping %s: required metadata '%s' is missing", self, prop ) return False + if getattr(self, prop) in (None, ""): + logger.error("Skipping %s: required metadata '%s' is empty", self, prop) + return False return True def _has_valid_slug(self) -> bool: diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 9dfa53f0..0ea55154 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -81,17 +81,22 @@ class TestPage(TestBase): self.assertEqual(page.content, TEST_CONTENT) def test_mandatory_properties(self): - # If the title is not set, must throw an exception. + # A missing title must make the content invalid. page = Page("content") self.assertFalse(page._has_valid_mandatory_properties()) - # An empty or `None` title must be treated the same as a missing title. + self.assertLogCountEqual( + count=1, + msg="Skipping .*: required metadata 'title' is missing", + level=logging.ERROR, + ) + # So must an empty or `None` title, with a message saying it is empty. for title in ("", None): with self.subTest(title=title): page = Page("content", metadata={"title": title}) self.assertFalse(page._has_valid_mandatory_properties()) self.assertLogCountEqual( - count=3, - msg="Skipping .*: could not find information about 'title'", + count=2, + msg="Skipping .*: required metadata 'title' is empty", level=logging.ERROR, ) page = Page("content", metadata={"title": "foobar"})