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

Columns exception, children of None variable #897

Closed
LukasKlement opened this issue Jul 12, 2019 · 2 comments

Comments

@LukasKlement
Copy link

commented Jul 12, 2019

I observe frequent exceptions with columned documents:

Request Method: | GET Django Version 2.2.3 AttributeError 'NoneType' object has no attribute 'children' /lib/python3.7/site-packages/weasyprint/layout/columns.py in columns_layout, line 165

The error is in:

/weasyprint/layout/columns.py in columns_layout new_box.children[-1].position_y - box.content_box_y() + new_box.children[-1].margin_height())

Basically, new_box = None hence the exception is thrown. I'm yet to produce a HTML document to reproduce this issue.

Edit: there are no floating elements

@liZe liZe added the crash label Jul 12, 2019

@smattheis

This comment has been minimized.

Copy link

commented Aug 27, 2019

I encountered the same issue. An example to reproduce the bug is as follows:

Example file example.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>
<body>
    <div style="position:absolute;">
        <div style="column-count: 2;">
            Lorem ipsum.
        </div>
    </div>
</body>
</html>

Bash on Mac OS X:

$ export LC_ALL=en_US.UTF-8; weasyprint example.html example.png
Traceback (most recent call last):
  File "/usr/local/bin/weasyprint", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/weasyprint/__main__.py", line 190, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/__init__.py", line 290, in write_png
    font_config=font_config)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/__init__.py", line 168, in render
    font_config)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/document.py", line 377, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/usr/local/lib/python3.7/site-packages/weasyprint/document.py", line 377, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/__init__.py", line 130, in layout_document
    pages = list(make_all_pages(context, root_box, html, pages, style_for))
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 798, in make_all_pages
    i, context, root_box, html, style_for)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 736, in remake_page
    page_number, page_state)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 561, in make_page
    absolute_layout(context, absolute_box, page, positioned_boxes)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/absolute.py", line 275, in absolute_layout
    absolute_box_layout(context, box, containing_block, fixed_boxes))
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/absolute.py", line 300, in absolute_box_layout
    new_box = absolute_block(context, box, containing_block, fixed_boxes)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/absolute.py", line 214, in absolute_block
    adjoining_margins=None)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 519, in block_container_layout
    adjoining_margins)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 65, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 81, in block_level_layout_switch
    adjoining_margins)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 110, in block_box_layout
    adjoining_margins)
  File "/usr/local/lib/python3.7/site-packages/weasyprint/layout/columns.py", line 165, in columns_layout
    new_box.children[-1].position_y - box.content_box_y() +
AttributeError: 'NoneType' object has no attribute 'children'

Note that it does NOT crash if the content is completely empty and also NOT if the content spans two columns:

Example file example.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>
<body>
    <div style="position:absolute;">
        <div style="column-count: 2;">
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </div>
    </div>
</body>
</html>

This produces the following example.png:

@liZe liZe added this to the 49 milestone Sep 4, 2019

@liZe liZe closed this in 4dc0b11 Sep 4, 2019

@liZe

This comment has been minimized.

Copy link
Member

commented Sep 4, 2019

The bug is fixed, but the rendering can be different from what browsers do, because:

  • The width of the absolute div fits the content in WeasyPrint, but it takes the whole width of the container in browsers. I don't know what this width should be.
  • Browsers don't respect widows and orphans, but the spec explicitly says that widows and orphans must be respected.
    Feel free to open new issues if there's anything wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.