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: 'BlockReplacedBox' object has no attribute 'copy_with_children' #836

Closed
nathandem opened this Issue Mar 27, 2019 · 3 comments

Comments

2 participants
@nathandem
Copy link

nathandem commented Mar 27, 2019

Hi,

For of all thanks for this great library, it really helps :)

For context, I ran into this exception after integrating a large css in my html. The template I have already had a specific css file (that I included in the <head> section of the page), also I passed it an additional stylesheet using the CSS class. Both were rendered fine.
To benefit from the base css style of the site of my company (fonts, etc), I decided to import a large css file as said above but I ran into this exception.

I think the problem comes from the lib, because it works fine when I render the same page on the browser (I mean passing the same context, styling but rendering locally).

The exception and its trace:

Traceback (most recent call last):
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/nathan/dev/bureauxlocaux/bureauxlocaux/apps/listings/views.py", line 364, in get_listing_pdf
    main_doc = html.render(stylesheets=[CSS(string=content_print_layout)])
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/__init__.py", line 168, in render
    font_config)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/document.py", line 366, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/document.py", line 366, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/__init__.py", line 133, in layout_document
    context, root_box, html, cascaded_styles, computed_styles, pages))
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 807, in make_all_pages
    i, context, root_box, html, cascaded_styles, computed_styles)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 744, in remake_page
    page_number, page_state)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 555, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 64, in block_level_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 80, in block_level_layout_switch
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 134, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 515, in block_container_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 64, in block_level_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 80, in block_level_layout_switch
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 134, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 515, in block_container_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 64, in block_level_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 80, in block_level_layout_switch
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 134, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 515, in block_container_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 64, in block_level_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 80, in block_level_layout_switch
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 134, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 515, in block_container_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 64, in block_level_layout
    adjoining_margins)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 95, in block_level_layout_switch
    device_size, page_is_empty, absolute_boxes, fixed_boxes)
  File "/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/flex.py", line 132, in flex_layout
    new_child = child.copy_with_children(child.children)
AttributeError: 'BlockReplacedBox' object has no attribute 'copy_with_children'

Here are the local variables around the exception:

absolute_boxes | []
available_cross_space | 659.8638550381396
available_main_space | 627.7996850393702
axis | 'width'
blocks | <module 'weasyprint.layout.blocks' from '/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/blocks.py'>
box | <FlexBox div>
child | <BlockReplacedBox img>
child_skip_stack | None
children | [<BlockBox h2>, <BlockReplacedBox img>]
containing_block | <BlockBox div>
content_size | 78.83984375
context | <weasyprint.layout.LayoutContext object at 0x12286dd68>
cross | 'height'
device_size | (793.7007874015749, 1122.5196850393702)
fixed_boxes | []
flex_basis | 'content'
main_flex_direction | 'width'
main_space | 659.8638550381396
margin_bottom | 0
margin_left | 0
margin_right | 0
margin_top | 0
max_position_y | 1028.0314960629921
new_child | <BlockBox h2>
original_skip_stack | None
page_is_empty | False
parent_box | <FlexBox div>
preferred | <module 'weasyprint.layout.preferred' from '/Users/nathan/.virtualenvs/bureauxlocaux/lib/python3.7/site-packages/weasyprint/layout/preferred.py'>
resume_at | None
skip_stack | None
specified_size | inf

In can provide the html if it helps (but the problem seems to be generic). Concerning the large css however, it can't really copy-paste it here because it is too large (+10k lines after preprocessing :p).

Thanks!

@liZe

This comment has been minimized.

Copy link
Member

liZe commented Mar 27, 2019

Hi,

Hello

For of all thanks for this great library, it really helps :)

You're welcome!

I think the problem comes from the lib,

You're right, and I have good news: it's already been fixed in e487a98! You can try the current master branch and tell me if it fixes this crash.

@liZe liZe added the crash label Mar 27, 2019

@liZe liZe added this to the 47 milestone Mar 27, 2019

@nathandem

This comment has been minimized.

Copy link
Author

nathandem commented Mar 27, 2019

I confirm that it works fine 👍

Do you plan to release master in the near future in pypi?

@liZe

This comment has been minimized.

Copy link
Member

liZe commented Mar 27, 2019

I confirm that it works fine

🎉

Do you plan to release master in the near future in pypi?

Probably not before a couple of weeks. Before that, you can install the current master branch with pip install git+https://github.com/Kozea/WeasyPrint.git.

@liZe liZe closed this Mar 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.