pelican icon indicating copy to clipboard operation
pelican copied to clipboard

Pelican creating undefined setting `STATIC_LANG_SAVE_AS` raises an error

Open ungual opened this issue 3 years ago • 3 comments

Hello,

I'm working on a multilang Pelican website. I want the first folder after content/ to be passed as the lang metadata, and the rest of the folders to be the category (here using nested categories with the more-categories plugin). So an article placed in fr/event/2022/my-event.md has lang = fr, and category = event/2022.

In order to do so, I'm using the PATH_METADATA settings to extract them using the following regex:

PATH_METADATA = '^(?P<lang>.+?)\/(?P<category>.*)\/.*'

Pelican write the output articles and pages as it should, but at the step of cloning static content it encounters an error. If I remove static content at all (STATIC_PATHS = []), then everything generates perfectly. But if i had back the images (STATIC_PATHS = [images]), then i get this error:

CRITICAL: 'STATIC_LANG_SAVE_AS'

which is weird because this setting does not exist. I figured out it was happening while calling the _expand_settings function at line 215 of content.py in the source file, creating this non-existing setting by merging two variables (klass and key).

I was able to bypass this issue by declaring them in the pelicanconf.py like this

STATIC_LANG_SAVE_AS = STATIC_LANG_URL = '{path}'

but this feels so wrong.

Anyone has an idea of what causes this _expand_settings function to be called with klass = STATIC and key = LANG_SAVE_AS and creating this non-existing setting? Could it be that PATH_METADATA is applied to images, giving them a wrong lang attribute in this configuration which is latter calling for a key = LANG_SAVE_AS with klass = STATIC ?

ungual avatar Aug 24 '22 16:08 ungual

Can you share the full traceback by running pelican with --debug?

avaris avatar Aug 25 '22 00:08 avaris

yes of course, here it is

CRITICAL: 'STATIC_LANG_SAVE_AS'
Traceback (most recent call last):
  File "/home/dorian/.local/bin/pelican", line 8, in <module>
    sys.exit(main())
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/__init__.py", line 527, in main
    pelican.run()
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/__init__.py", line 125, in run
    p.generate_output(writer)
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/generators.py", line 828, in generate_output
    if self._file_update_required(sc):
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/generators.py", line 855, in _file_update_required
    save_as = os.path.join(self.output_path, staticfile.save_as)
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/contents.py", line 572, in save_as
    return super().save_as
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/contents.py", line 446, in save_as
    return self.get_url_setting('save_as')
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/contents.py", line 225, in get_url_setting
    return self._expand_settings(key)
  File "/home/dorian/.local/lib/python3.8/site-packages/pelican/contents.py", line 219, in _expand_settings
    return self.settings[fq_key].format(**self.url_format)
KeyError: 'STATIC_LANG_SAVE_AS'

ungual avatar Aug 25 '22 11:08 ungual

It's called with 'save_as' as expected, so... it appears like you have a Static_Lang class that's replacing the built in Static class? That is odd, I'm not sure where that's coming from. PATH_METADATA should not have any effect. I'd suspect a plugin to be the culprit. Can you show your config file?

avaris avatar Aug 28 '22 00:08 avaris

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

stale[bot] avatar Nov 02 '22 08:11 stale[bot]