Skip to content

Conversation

@Lucas-C
Copy link
Contributor

@Lucas-C Lucas-C commented Mar 18, 2025

This is a port of PR getpelican/pelican-plugins#1411 to this repo.

Without this fix, when an article contains an <img> with no src attribute, Pelican crashes:

Traceback (most recent call last):
  File "~/.local/share/virtualenvs/ludochaordic/lib/python3.10/site-packages/pelican/__init__.py", line 679, in main
    pelican.run()
  File "~/.local/share/virtualenvs/ludochaordic/lib/python3.10/site-packages/pelican/__init__.py", line 133, in run
    signals.all_generators_finalized.send(generators)
  File "~/.local/share/virtualenvs/ludochaordic/lib/python3.10/site-packages/blinker/base.py", line 307, in send
    result = receiver(sender, **kwargs)
  File "~/pelican-plugins/representative_image/representative_image.py", line 48, in run_plugin
    images_extraction(article)
  File "~/pelican-plugins/representative_image/representative_image.py", line 35, in images_extraction
    representativeImage = imageTag['src']
  File "~/.local/share/virtualenvs/ludochaordic/lib/python3.10/site-packages/bs4/element.py", line 2206, in __getitem__
    return self.attrs[key]
KeyError: 'src'
[15:38:22] CRITICAL [15:38:22] [pelican] CRITICAL KeyError: 'src'

@Lucas-C Lucas-C force-pushed the avoid-critical-error-when-img-has-no-src branch from 6110d68 to 78e4ac8 Compare March 18, 2025 14:58
Copy link
Contributor

@justinmayer justinmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix, Lucas! 🏅

@justinmayer justinmayer merged commit de3522d into main Mar 18, 2025
14 checks passed
@justinmayer justinmayer deleted the avoid-critical-error-when-img-has-no-src branch March 18, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants