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

AttributeError: 'BlockBox' object has no attribute 'width' #1239

Closed
austinw-fineart opened this issue Oct 21, 2020 · 4 comments
Closed

AttributeError: 'BlockBox' object has no attribute 'width' #1239

austinw-fineart opened this issue Oct 21, 2020 · 4 comments
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@austinw-fineart
Copy link

It appears to be caused by any list item element inside of a running element.
Minimum reproducible example:

<style>
  @page {
    @top-center {
      content: element(header);
      width: 100%;
    }
  }
</style>
<div style="position: running(header);">
  <ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
  </ul>
</div>
Traceback
Traceback (most recent call last):
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\__main__.py", line 216, in <module>
    main()
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\__main__.py", line 212, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\__init__.py", line 208, in write_pdf
    return self.render(
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\__init__.py", line 166, in render
    return Document._render(
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\document.py", line 393, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\document.py", line 393, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\__init__.py", line 184, in layout_document
    layout_backgrounds(page, context.get_image_from_uri)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\backgrounds.py", line 241, in layout_backgrounds
    layout_box_backgrounds(page, page, get_image_from_uri)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\backgrounds.py", line 57, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\backgrounds.py", line 57, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\backgrounds.py", line 57, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  [Previous line repeated 2 more times]
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\backgrounds.py", line 54, in layout_box_backgrounds
    resolve_radii_percentages(box)
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\layout\percentages.py", line 148, in resolve_radii_percentages
    rx = percentage(rx, box.border_width())
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\formatting_structure\boxes.py", line 148, in border_width
    return self.padding_width() + self.border_left_width + \
  File "C:\Users\austinw\AppData\Local\Programs\Python\Python39\lib\site-packages\weasyprint\formatting_structure\boxes.py", line 140, in padding_width
    return self.width + self.padding_left + self.padding_right
AttributeError: 'BlockBox' object has no attribute 'width'
@liZe liZe added the crash Problems preventing documents from being rendered label Oct 21, 2020
@mpth
Copy link

mpth commented Dec 14, 2020

Just ran into the same error message. Will try to narrow down to a minimal repro and report back...

@mpth
Copy link

mpth commented Dec 16, 2020

Hey there,

here is a repro - in my case the error seems to be related to a absolute positioned element in the running header. Once I change the .logo position to something else it renders fine:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <style>
        header {
            position: running(header);
        }

        @page {

            @top-center {
                content: element(header);
            }
        }


        .logo {
            position: absolute;
            top: 0;
            right: 0;
        }
    </style>
</head>

<body>

    <header>
        <div class="logo">
        </div>
    </header>

    <h1>My title</h1>

</body>

</html>
Trace
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/local/lib/python3.7/dist-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/site/weasy/serve.py", line 33, in dev
    return render_app(env, sr)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/tools/renderer.py", line 96, in app
    return make_response(get_data()[1].encode('utf-8'))
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/tools/renderer.py", line 86, in get_data
    html.write_png(png)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py", line 324, in write_png
    counter_style=counter_style, image_cache=image_cache)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py", line 174, in render
    optimize_images, font_config, counter_style, image_cache)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/document.py", line 406, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/document.py", line 406, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/__init__.py", line 207, in layout_document
    layout_backgrounds(page, context.get_image_from_uri)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/backgrounds.py", line 247, in layout_backgrounds
    layout_box_backgrounds(page, page, get_image_from_uri)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/backgrounds.py", line 56, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/backgrounds.py", line 56, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/backgrounds.py", line 56, in layout_box_backgrounds
    layout_box_backgrounds(page, child, get_image_from_uri)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/backgrounds.py", line 52, in layout_box_backgrounds
    resolve_radii_percentages(box)
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/layout/percentages.py", line 150, in resolve_radii_percentages
    rx = percentage(rx, box.border_width())
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/formatting_structure/boxes.py", line 145, in border_width
    return self.padding_width() + self.border_left_width + \
  File "/usr/local/lib/python3.7/dist-packages/weasyprint/formatting_structure/boxes.py", line 137, in padding_width
    return self.width + self.padding_left + self.padding_right
AttributeError: 'BlockBox' object has no attribute 'width'

Hope this is helpful!

@jmtd
Copy link

jmtd commented Jan 24, 2022

I've hit this with v54.0

@liZe
Copy link
Member

liZe commented Jan 24, 2022

Duplicate of #1540, as list markers are absolutely positioned.

@liZe liZe closed this as completed Jan 24, 2022
@liZe liZe added this to the 54.1 milestone Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

4 participants