Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure _DISCARDED is not being cached. Fix #2825 #2926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pelican/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,9 @@ def read_file(self, base_path, path, content_class=Page, fmt=None,
content, reader_metadata = self.get_cached_data(path, (None, None))
if content is None:
content, reader_metadata = reader.read(path)
reader_metadata = _filter_discardable_metadata(reader_metadata)
self.cache_data(path, (content, reader_metadata))
metadata.update(_filter_discardable_metadata(reader_metadata))
metadata.update(reader_metadata)

if content:
# find images with empty alt
Expand Down
4 changes: 4 additions & 0 deletions pelican/tests/content/article_with_markdown_and_empty_tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Title: Article with markdown and empty tags
Tags:

This is some content.
3 changes: 3 additions & 0 deletions pelican/tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def test_generate_context(self):
['This is a super article !', 'published', 'yeah', 'article'],
['This is a super article !', 'published', 'Default', 'article'],
['Article with an inline SVG', 'published', 'Default', 'article'],
['Article with markdown and empty tags', 'published', 'Default',
'article'],
['This is an article with category !', 'published', 'yeah',
'article'],
['This is an article with multiple authors!', 'published',
Expand Down Expand Up @@ -569,6 +571,7 @@ def test_article_order_by(self):
'Article title',
'Article with Nonconformant HTML meta tags',
'Article with an inline SVG',
'Article with markdown and empty tags',
'Article with markdown and nested summary metadata',
'Article with markdown and summary metadata multi',
'Article with markdown and summary metadata single',
Expand Down
18 changes: 18 additions & 0 deletions pelican/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ReaderTest(unittest.TestCase):

def read_file(self, path, **kwargs):
# Isolate from future API changes to readers.read_file

r = readers.Readers(settings=get_settings(**kwargs))
return r.read_file(base_path=CONTENT_PATH, path=path)

Expand Down Expand Up @@ -795,6 +796,23 @@ def test_typogrify_dashes_config(self):
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)

def test_metadata_has_no_discarded_data(self):
md_filename = 'article_with_markdown_and_empty_tags.md'

r = readers.Readers(cache_name='cache', settings=get_settings(
CACHE_CONTENT=True))
page = r.read_file(base_path=CONTENT_PATH, path=md_filename)

__, cached_metadata = r.get_cached_data(
_path(md_filename), (None, None))

expected = {
'title': 'Article with markdown and empty tags'
}
self.assertEqual(cached_metadata, expected)
self.assertNotIn('tags', page.metadata)
self.assertDictHasSubset(page.metadata, expected)


class HTMLReaderTest(ReaderTest):
def test_article_with_comments(self):
Expand Down