Skip to content

Commit 8849721

Browse files
authored
Ensure _DISCARDED is not being cached. Fix #2825 (#2926)
Filtration is now being applied before caching the metadata, solving the issue where _DISCARD objects from previous runs were being retrieved from cache.
1 parent 0da8659 commit 8849721

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

pelican/readers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,9 @@ def read_file(self, base_path, path, content_class=Page, fmt=None,
571571
content, reader_metadata = self.get_cached_data(path, (None, None))
572572
if content is None:
573573
content, reader_metadata = reader.read(path)
574+
reader_metadata = _filter_discardable_metadata(reader_metadata)
574575
self.cache_data(path, (content, reader_metadata))
575-
metadata.update(_filter_discardable_metadata(reader_metadata))
576+
metadata.update(reader_metadata)
576577

577578
if content:
578579
# find images with empty alt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Title: Article with markdown and empty tags
2+
Tags:
3+
4+
This is some content.

pelican/tests/test_generators.py

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ def test_generate_context(self):
265265
['This is a super article !', 'published', 'yeah', 'article'],
266266
['This is a super article !', 'published', 'Default', 'article'],
267267
['Article with an inline SVG', 'published', 'Default', 'article'],
268+
['Article with markdown and empty tags', 'published', 'Default',
269+
'article'],
268270
['This is an article with category !', 'published', 'yeah',
269271
'article'],
270272
['This is an article with multiple authors!', 'published',
@@ -569,6 +571,7 @@ def test_article_order_by(self):
569571
'Article title',
570572
'Article with Nonconformant HTML meta tags',
571573
'Article with an inline SVG',
574+
'Article with markdown and empty tags',
572575
'Article with markdown and nested summary metadata',
573576
'Article with markdown and summary metadata multi',
574577
'Article with markdown and summary metadata single',

pelican/tests/test_readers.py

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ReaderTest(unittest.TestCase):
1818

1919
def read_file(self, path, **kwargs):
2020
# Isolate from future API changes to readers.read_file
21+
2122
r = readers.Readers(settings=get_settings(**kwargs))
2223
return r.read_file(base_path=CONTENT_PATH, path=path)
2324

@@ -795,6 +796,23 @@ def test_typogrify_dashes_config(self):
795796
self.assertEqual(page.content, expected)
796797
self.assertEqual(page.title, expected_title)
797798

799+
def test_metadata_has_no_discarded_data(self):
800+
md_filename = 'article_with_markdown_and_empty_tags.md'
801+
802+
r = readers.Readers(cache_name='cache', settings=get_settings(
803+
CACHE_CONTENT=True))
804+
page = r.read_file(base_path=CONTENT_PATH, path=md_filename)
805+
806+
__, cached_metadata = r.get_cached_data(
807+
_path(md_filename), (None, None))
808+
809+
expected = {
810+
'title': 'Article with markdown and empty tags'
811+
}
812+
self.assertEqual(cached_metadata, expected)
813+
self.assertNotIn('tags', page.metadata)
814+
self.assertDictHasSubset(page.metadata, expected)
815+
798816

799817
class HTMLReaderTest(ReaderTest):
800818
def test_article_with_comments(self):

0 commit comments

Comments
 (0)