Blocks.py BlockBox has no attribute index
See original GitHub issueDear WeasyPrint-Team,
one more crash reduced enough to report:
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 839
in find_earlier_page_break resume_at = (new_child.index, resume_at)
AttributeError: 'BlockBox' object has no attribute 'index'
Traceback (most recent call last):
File "I:\yRuntimes-x64-msvc2017\Python\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "I:\yRuntimes-x64-msvc2017\Python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "I:\xClients\WeasyPrint\weasyprint\__main__.py", line 248, in <module>
main()
File "I:\xClients\WeasyPrint\weasyprint\__main__.py", line 239, in main
main_doc = getattr(html, 'render')(**kwargsRender)
File "I:\xClients\WeasyPrint\weasyprint\__init__.py", line 174, in render
optimize_images, font_config, counter_style, image_cache)
File "I:\xClients\WeasyPrint\weasyprint\document.py", line 401, in _render
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "I:\xClients\WeasyPrint\weasyprint\document.py", line 401, in <listcomp>
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "I:\xClients\WeasyPrint\weasyprint\layout\__init__.py", line 123, in layout_document
pages = list(make_all_pages(context, root_box, html, pages))
File "I:\xClients\WeasyPrint\weasyprint\layout\pages.py", line 800, in make_all_pages
page, resume_at = remake_page(i, context, root_box, html)
File "I:\xClients\WeasyPrint\weasyprint\layout\pages.py", line 739, in remake_page
page_number, page_state)
File "I:\xClients\WeasyPrint\weasyprint\layout\pages.py", line 550, in make_page
positioned_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 60, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 74, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 127, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 508, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 60, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 74, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 127, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 508, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 60, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 74, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 127, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 553, in block_container_layout
new_children, absolute_boxes, fixed_boxes)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 825, in find_earlier_page_break
child.children, absolute_boxes, fixed_boxes)
File "I:\xClients\WeasyPrint\weasyprint\layout\blocks.py", line 839, in find_earlier_page_break
resume_at = (new_child.index, resume_at)
AttributeError: 'BlockBox' object has no attribute 'index'
<html>
<head>
<style>
.colCount2{
column-count:2;
}
.nobreak{
break-after:avoid;
}
.box{
border:1px solid black;
width:350px;
height:350px;
}
</style>
</head>
<body>
<section>
<p>A</p>
</section>
<section>
<div class="colCount2">
<div class="nobreak">
<div class="box"></div>
</div>
<div class="nobreak">
<div class="box"></div>
<p>a</p>
<p>a</p>
</div>
</div>
<div class="colCount2">
<div class="nobreak">
<div class="box"></div>
<p>a</p>
</div>
</div>
</section>
</body>
</html>
Please let me know, if I can do anything different in preparing/reducing these examples to make your life easier.
Thanks again for your efforts!
I wish you a good weekend,
Johannes
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Django: 'module' object has no attribute 'index' - Stack Overflow
Import the urls.py module into your view. like this; from django.http import HttpResponse from . import urls def index(request): return ...
Read more >9 Visual formatting model - W3C
The visual formatting model does not specify all aspects of formatting (e.g., ... the <p> generates a block box, with several inline boxes...
Read more >The box model - Learn web development | MDN
A paragraph with a border added in CSS. The browser renders this as a block box. · A list, which is laid out...
Read more >HTML5 Element Index - HTML5 Doctor
If the a element has no href attribute, then the element represents a placeholder for ... the element is expected to render as...
Read more >Frequently Asked Questions - Snakemake - Read the Docs
Snakemake does not connect my rules as I have expected, what can I do to debug my ... How do I access elements...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Reason to crash is the same as in #1168.
When WeasyPrint paginates a multi-column block,
columns_layout
wraps the columns into an anonymous BlockBox.When trying to find an opportunity to break a multi-column box,
find_earlier_page_break
recurses the given children and their grandchildren. Sooner or later it will bump into such an anonymous column BlockBox which (of course) doesn’t have no index in its non-laid-out parent.Thus: AttributeError.
The solution is skipping
if child.is_column
like we already do forchild.is_header or child.is_footer
. After all we cannot break a multi-column block at an arbitrary position in an arbitrary column… that’s the job ofcolumns_layout
, i.e. the multi-column block itself.@LiZe Are there more anonymous BlockBoxes without index in their non-laid-out parent lurking? Should we continue
if !hasattr(child, 'index')
?@mag-chang Hi!
If you’re still interested in this issue, could you please try c35a629 and see if it fixes your problem?
Thank you!