Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with 2.0.0rc2: AttributeError("'str' object has no attribute 'attributes'") #1522

Closed
lazka opened this issue Sep 4, 2023 · 6 comments · Fixed by #1528
Closed

Error with 2.0.0rc2: AttributeError("'str' object has no attribute 'attributes'") #1522

lazka opened this issue Sep 4, 2023 · 6 comments · Fixed by #1528
Assignees
Labels
Bug A bug Needed: replication Bug replication is required
Milestone

Comments

@lazka
Copy link

lazka commented Sep 4, 2023

Problem

Theme error:
An error happened in rendering the page api/aac.
Reason: AttributeError("'str' object has no attribute 'attributes'")

With verbose logs:

Traceback (most recent call last):
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 1098, in handle_page
    output = self.templates.render(templatename, ctx)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/sphinx/jinja2glue.py", line 196, in render
    return self.environment.get_template(template).render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/sphinx/themes/basic/page.html", line 10, in top-level template code
    {%- extends "layout.html" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/sphinx_rtd_theme/layout.html", line 36, in top-level template code
    {{ css_tag(cssfile) }}
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/jinja2/sandbox.py", line 393, in call
    return __context.call(__obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lazka/.cache/pypoetry/virtualenvs/mutagen-z6FbeZMH-py3.11/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 1197, in css_tag
    for key in sorted(css.attributes):
                      ^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'attributes'

Reproducible Project

https://github.com/quodlibet/mutagen/tree/main/docs

Expected Results

the docs build

Environment Info

  • Python Version: 3.11.5
  • Sphinx Version: 6.2.1
  • RTD Theme Version: 2.0.0rc2
@lazka lazka added Bug A bug Needed: replication Bug replication is required labels Sep 4, 2023
leplatrem added a commit to leplatrem/sphinx_rtd_theme that referenced this issue Sep 28, 2023
@agjohnson
Copy link
Collaborator

This is due to a recent change, #1519. I haven't looked into what is happening here, but it seems the css_tag isn't safe on it's own.

@lazka are you setting any of the Sphinx CSS configuration options in your project's settings? I'm guessing the template logic we had before is safer for a larger number of projects, as there is some variance in how the CSS configuration options can be configured.

@agjohnson agjohnson added this to the 2.0 milestone Sep 28, 2023
@lazka
Copy link
Author

lazka commented Sep 28, 2023

@humitos humitos self-assigned this Oct 10, 2023
@humitos
Copy link
Member

humitos commented Oct 10, 2023

We made the change in #1519 due to #1502. I don't think we can just revert those changes because we will be breaking compatibility with newer Sphinx versions. We will need to dig a little more on this issue and find a solution that works for Sphinx>5

@mitya57
Copy link
Contributor

mitya57 commented Oct 10, 2023

We made the change in #1519 due to #1502. I don't think we can just revert those changes because we will be breaking compatibility with newer Sphinx versions. We will need to dig a little more on this issue and find a solution that works for Sphinx>5

Only the part about extra_css_files needs to be reverted, the new code for css_files works and can be left as is. See my comments in #1528.

humitos added a commit to leplatrem/sphinx_rtd_theme that referenced this issue Oct 23, 2023
agjohnson added a commit that referenced this issue Oct 24, 2023
* Fix #1522: fix attribute error if css is str

* Revert "Fix #1522: fix attribute error if css is str"

This reverts commit b22a77f.

* Use `css_tag` only for standard CSS files from Sphinx

... and keep using the custom `link` HTML tag for CSS files included via the
HTML theme option `extra_css_files`.

* Normalize template variables

---------

Co-authored-by: Manuel Kaufmann <humitos@gmail.com>
Co-authored-by: Anthony Johnson <aj@ohess.org>
@humitos
Copy link
Member

humitos commented Oct 24, 2023

@lazka Hi! 2.0.0rc3 is now out with a fix for this case. Would you mind giving it a try and let us know if it works as expected? 👍🏼

@lazka
Copy link
Author

lazka commented Oct 26, 2023

works nicely now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug Needed: replication Bug replication is required
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants