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

Assertion error with <th> tags in v54.X #1586

Closed
mfisco opened this issue Mar 2, 2022 · 5 comments
Closed

Assertion error with <th> tags in v54.X #1586

mfisco opened this issue Mar 2, 2022 · 5 comments
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@mfisco
Copy link

mfisco commented Mar 2, 2022

Hi,

I have a django project using weasyprint and when I upgraded from version 53.4 to 54.X I recieve an assertion error. I've determined it only occurs when using <th> tags in the templates. Specifically, it's caused when the value ofalign is equal to -webkit-match-parent within the function text_align located in weasyprint/layout/inline.py.

I was able to prevent the exception occuring by changing all <th> tags to <td> but believe it may be similar to #1538 as I am also using bootstrap v4.5.3

Context:

Python Code:

def generate_pdf(template_name, context, http_request=None):
    base_url = "/"

    if http_request:
        base_url = http_request.build_absolute_uri()

    html_string = render_to_string(template_name, context)
    html_obj = HTML(string=html_string, base_url=base_url, url_fetcher=custom_url_fetcher)
    return html_obj.write_pdf(presentational_hints=True)

Traceback:

  File "/home/runner/work/DjangoProject/Project/src/base/utils/files.py", line 43, in generate_pdf
    return html_obj.write_pdf(presentational_hints=True)
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/__init__.py", line 183, in write_pdf
    self.render(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/__init__.py", line 134, in render
    return Document._render(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/document.py", line 930, in _render
    [Page(page_box) for page_box in page_boxes],
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/document.py", line 930, in <listcomp>
    [Page(page_box) for page_box in page_boxes],
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/__init__.py", line 133, in layout_document
    pages = list(make_all_pages(context, root_box, html, pages))
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/page.py", line 855, in make_all_pages
    page, resume_at = remake_page(i, context, root_box, html)
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/page.py", line 792, in remake_page
    page, resume_at, next_page = make_page(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/page.py", line 590, in make_page
    root_box, resume_at, next_page, _, _ = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 70, in block_level_layout_switch
    return block_box_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 112, in block_box_layout
    result = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 641, in block_container_layout
    next_page, new_children) = _in_flow_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 449, in _in_flow_layout
    collapsing_through) = block_level_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 56, in block_level_layout
    return block_level_layout_switch(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 66, in block_level_layout_switch
    return table_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/table.py", line 533, in table_layout
    all_groups_layout())
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/table.py", line 435, in all_groups_layout
    header, resume_at, next_page = group_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/table.py", line 166, in group_layout
    new_cell, cell_resume_at, _, _, _ = block_container_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 631, in block_container_layout
    abort, stop, resume_at, position_y = _linebox_layout(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/block.py", line 304, in _linebox_layout
    for i, (line, resume_at) in enumerate(lines_iterator):
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/inline.py", line 43, in iter_line_boxes
    line, resume_at = get_next_linebox(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/inline.py", line 114, in get_next_linebox
    offset_x = text_align(
  File "/home/runner/work/DjangoProject/Project/.venv/lib/python3.9/site-packages/weasyprint/layout/inline.py", line 1143, in text_align
    assert align == 'end'
AssertionError
@liZe
Copy link
Member

liZe commented Mar 2, 2022

Hello,

This bug really looks like #1538. Did you try the latest version of WeasyPrint (54.2)?

@liZe
Copy link
Member

liZe commented Mar 2, 2022

Specifically, it's caused when the value ofalign is equal to -webkit-match-parent within the function text_align located in weasyprint/layout/inline.py.

Sorry, I didn’t read your comment carefully. This bug is probably different, we have to check this.

@mfisco
Copy link
Author

mfisco commented Mar 2, 2022

Yes, I tried it with 54.1 and 54.2 and the problem persists. Let me know if you'd like be to add the css file that's causing it (it's kinda large haha).

@liZe liZe added the crash Problems preventing documents from being rendered label Mar 2, 2022
@liZe liZe added this to the 54.3 milestone Mar 2, 2022
liZe added a commit that referenced this issue Mar 2, 2022
@liZe
Copy link
Member

liZe commented Mar 2, 2022

The bug was already fixed and tested in master as a side effect of #1524. It’s now fixed and tested in the 54.x branch too, using some old-style code to avoid possible regressions that #1524 could introduce.

Before 54.3 is released, you can apply the patch, or try the 54.x (safe) or master (less safe) branches.

Thanks for the bug report!

@liZe liZe closed this as completed Mar 2, 2022
@mfisco
Copy link
Author

mfisco commented Mar 2, 2022

Awesome thanks @liZe!

m-alorda added a commit to m-alorda/calendar-fetcher that referenced this issue Mar 20, 2022
Until weasyprint `54.3` version is released, `th` elements cannot be used.
See: <Kozea/WeasyPrint#1586>
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

2 participants