seo icon indicating copy to clipboard operation
seo copied to clipboard

Error: Authors can be empty!

Open Sogolumbo opened this issue 2 years ago • 3 comments

I get the following error:

[...]
File "...seo\seo_enhancer\html_enhancer\article_schema_creator.py", line 17, in __init__
    self._author = author.name
AttributeError: 'NoneType' object has no attribute 'name'

The reason for the error is: The implicit assumption that the object author is not empty is wrong because there's the option to have no authors for an article.

Sogolumbo avatar Jul 15 '22 16:07 Sogolumbo

Proposed fix for this line:

    def __init__(self, author, title, category, date, logo, image, sitename):
        if author:
            self._author = author.name
        else:
            self._author=''
        self._title = title
        self._category = category.name
        self._publication_date = date
        self._logo = logo
        self._image = image
        self._sitename = sitename

Sogolumbo avatar Jul 15 '22 16:07 Sogolumbo

Hi @Sogolumbo, thanks for raising this.

To fix this, I would go for this here:

        if self._author:
            schema_article["author"] = {"@type": "Person", "name": self._author.name}

Same issue for category.

Feel free to open a PR with according tests if you want to contribute :)

MaevaBrunelles avatar Aug 02 '22 20:08 MaevaBrunelles

Hello,

Was it fixed? Doesn't look like it but maybe I'm wrong. I use Pelican but I don't set Author because I'm the only one writing, and I'll be interested to look at this particular case.

Let me know!

frica avatar Mar 22 '24 13:03 frica