From 673e33840d124bc274805fe8ca3acb199d5c9cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Sep 2018 12:56:24 +0200 Subject: [PATCH] Don't process metadata links before all files are present. The refresh_metadata_intersite_links() is called again later, so this bit was only causing everything to be processed twice. Besides that, it makes the processing dependent on file order -- in particular, when metadata references a file that was not parsed yet, it reported an "Unable to find" warning. But everything is found in the second pass, so this only causes a superflous false warning and no change to the output. The related test now needs to call the refresh_metadata_intersite_links() explicitly. That function is called from Pelican.run() and all generators but the test processes just one page so it has no chance of being called implicitly. Related discussion: https://github.com/getpelican/pelican/pull/2288/files#r204337359 --- pelican/contents.py | 4 ---- pelican/tests/test_contents.py | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 327adc72..dd2a74fa 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -142,10 +142,6 @@ class Content(object): if not hasattr(self, 'status'): self.status = getattr(self, 'default_status', None) - if (len(self._context.get('generated_content', [])) > 0 or - len(self._context.get('static_content', [])) > 0): - self.refresh_metadata_intersite_links() - signals.content_object_init.send(self) def __str__(self): diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 21766359..da1a6ae2 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -333,6 +333,10 @@ class TestPage(LoggedTestCase): args['metadata']['custom'] = parsed args['context']['localsiteurl'] = 'http://notmyidea.org' p = Page(**args) + # This is called implicitly from all generators and Pelican.run() once + # all files are processed. Here we process just one page so it needs + # to be called explicitly. + p.refresh_metadata_intersite_links() self.assertEqual(p.summary, linked) self.assertEqual(p.custom, linked)