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

TypeError: can only concatenate str (not "float") to str (after update from 61.2 to 62.1) #2154

Closed
Zerotask opened this issue May 13, 2024 · 5 comments
Labels
crash Problems preventing documents from being rendered

Comments

@Zerotask
Copy link

Zerotask commented May 13, 2024

After updating form 61.2 to 62.0/62.1 our code does not create the PDF anymore.

content = weasyprint.HTML(string=html_content, base_url=base_url).write_pdf(
    stylesheets=[
        weasyprint.CSS(settings.BASE_DIR / "static" / "css/protocol.css"),
    ],
)
TypeError: can only concatenate str (not "float") to str

File "/Users/hintermayer/***.py", line 500, in _create_protocol
content = weasyprint.HTML(string=html_content, base_url=base_url).write_pdf(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/init.py", line 259, in write_pdf
self.render(font_config, counter_style, **options)
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/init.py", line 216, in render
return Document._render(self, font_config, counter_style, options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/document.py", line 262, in _render
[Page(page_box) for page_box in page_boxes],
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/init.py", line 130, in layout_document
pages = list(make_all_pages(context, root_box, html, pages))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/page.py", line 906, in make_all_pages
page, resume_at = remake_page(i, context, root_box, html)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/page.py", line 844, in remake_page
page, resume_at, next_page = make_page(
^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/page.py", line 646, in make_page
root_box, resume_at, next_page, _, _, _ = block_level_layout(
^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
return block_level_layout_switch(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
return block_box_layout(
^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
result = block_container_layout(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 714, in block_container_layout
next_page, new_children, new_max_lines) = _in_flow_layout(
^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 506, in _in_flow_layout
collapsing_through, max_lines) = block_level_layout(
^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
return block_level_layout_switch(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
return block_box_layout(
^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
result = block_container_layout(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 714, in block_container_layout
next_page, new_children, new_max_lines) = _in_flow_layout(
^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 506, in _in_flow_layout
collapsing_through, max_lines) = block_level_layout(
^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
return block_level_layout_switch(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 75, in block_level_layout_switch
return block_box_layout(
^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 124, in block_box_layout
result = block_container_layout(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 714, in block_container_layout
next_page, new_children, new_max_lines) = _in_flow_layout(
^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 506, in _in_flow_layout
collapsing_through, max_lines) = block_level_layout(
^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
return block_level_layout_switch(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 86, in block_level_layout_switch
result = grid_layout(
^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/grid.py", line 960, in grid_layout
rows_sizes = _resolve_tracks_sizes(
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/grid.py", line 392, in _resolve_tracks_sizes
child, _, _, _, _, _ = block_level_layout(
^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 59, in block_level_layout
return block_level_layout_switch(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/block.py", line 86, in block_level_layout_switch
result = grid_layout(
^^^^^^^^^^^^
File "/Users/hintermayer/Library/Caches/pypoetry/virtualenvs/platform-JeoL_1Z5-py3.12/lib/python3.12/site-packages/weasyprint/layout/grid.py", line 1112, in grid_layout
child.margin_left + child.border_left_width + child.padding_left +
TypeError: can only concatenate str (not "float") to str

@liZe
Copy link
Member

liZe commented May 13, 2024

Hi!

Could you please share your HTML and CSS files, so that we can reproduce the bug?

@Zerotask
Copy link
Author

Zerotask commented May 13, 2024

The HTML file is split into several django templates. It's nothing fancy

Here's the css code (most of it is based on tailwindcss):

Details

@page {
@bottom-right {
content: counter(page);
height: 1cm;
text-align: center;
width: 1cm;
}
@bottom-left {
content: "...";
height: 1cm;
font-size: 0.875rem;
}
@top-left {
content: string(heading);
color: #6b7280;
height: 1cm;
font-size: 0.875rem;
}
}

html {
font-family: Arial, sans-serif;
font-size: 11pt;
line-height: 1.6;
}

body {
margin: 0;
}

page {
background: white;
display: block;
margin: 0 auto 0.5cm;
box-shadow: 0 0 0.5cm rgba(0, 0, 0, 0.5);
page-break-before: always;
}

.page-break-before {
page-break-before: always;
}
.page-break-inside-avoid {
page-break-inside: avoid;
}

#header {
display: flex;
justify-content: space-between;
}

#address {
width: 50%;
padding-top: 1.5cm;
}

#date {
width: 50%;
text-align: right;
}

.m-1 {
margin: 0.25rem;
}

.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
}

.mx-auto {
margin-left: auto;
margin-right: auto;
}

.my-1 {
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}

.my-2 {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}

.my-3 {
margin-top: 0.75rem;
margin-bottom: 0.75rem;
}

.my-5 {
margin-top: 1.25rem;
margin-bottom: 1.25rem;
}

.mb-2 {
margin-bottom: 0.5rem;
}

.mb-20 {
margin-bottom: 5rem;
}

.mb-3 {
margin-bottom: 0.75rem;
}

.mb-4 {
margin-bottom: 1rem;
}

.mb-5 {
margin-bottom: 1.25rem;
}

.mb-8 {
margin-bottom: 2rem;
}

.ml-1 {
margin-left: 0.25rem;
}

.ml-3 {
margin-left: 0.75rem;
}

.ml-4 {
margin-left: 1rem;
}

.ml-auto {
margin-left: auto;
}

.mr-2 {
margin-right: 0.5rem;
}

.mr-4 {
margin-right: 1rem;
}

.mr-5 {
margin-right: 1.25rem;
}

.mr-6 {
margin-right: 1.5rem;
}

.mr-7 {
margin-right: 1.75rem;
}

.mt-16 {
margin-top: 4rem;
}

.mt-1cm {
margin-top: 1cm;
}

.mt-2cm {
margin-top: 2cm;
}

.mt-3cm {
margin-top: 3cm;
}

.mt-4cm {
margin-top: 4cm;
}

.mt-2 {
margin-top: 0.5rem;
}

.mt-3 {
margin-top: 0.75rem;
}

.mt-4 {
margin-top: 1rem;
}

.mt-5 {
margin-top: 1.25rem;
}

.mt-6 {
margin-top: 1.5rem;
}

.mt-8 {
margin-top: 2rem;
}

.pl-12 {
padding-left: 3rem;
}

.pl-3 {
padding-left: 0.75rem;
}

.pl-6 {
padding-left: 1.5rem;
}

.pl-10 {
padding-left: 2.5rem;
}

.pl-2 {
padding-left: 0.5rem;
}

.px-2 {
padding-left: 0.5rem/* 8px /;
padding-right: 0.5rem/
8px */;
}

.ml-0 {
margin-left: 0;
}

.ml-1cm {
margin-left: 1cm;
}

.col-span-1 {
grid-column: span 1 / span 1;
}

.w-16 {
width: 4rem;
}

.h-16 {
height: 4rem;
}

.mr-4 {
margin-right: 1rem;
}

.grid {
display: grid;
}

.grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}

.block {
display: block;
}

.inline-block {
display: inline-block;
}

.card {
display: grid;
grid-template-columns: 1fr;
}

.card-body {
display: grid;
gap: 0.5rem;
}

.card-title {
display: grid;
align-items: center;
gap: 0.5rem;
font-size: 1.25rem;
line-height: 1.75rem;
font-weight: 600;
}

.flex {
display: flex;
}

.flex-wrap {
flex-wrap: wrap;
}

.items-center {
align-items: center;
}

.justify-between {
justify-content: space-between;
}

.justify-center {
justify-content: center;
}

.text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}

.text-xs {
font-size: 0.75rem;
line-height: 1rem;
}

.text-base {
font-size: 1rem;
line-height: 1.5rem;
}

.text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}

.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}

.text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}

.bg-primary {
background-color: #39a980;
}

.bg-secondary {
background-color: #2a5d5c;
}

.max-w-full {
max-width: 100%;
}

.inline-flex {
display: inline-flex;
}

.no-underline {
text-decoration-line: none;
}

.text-black {
color: #000000;
}

.text-gray-500 {
color: #6b7280;
}

.content-item::after {
content: " " leader(".") " " target-counter(attr(href), page);
}
.section-heading {
string-set: heading content();
}

.object-scale-down {
object-fit: scale-down;
}

.h-32 {
height: 8rem /* 128px */;
}

.w-96 {
width: 24rem /* 384px */;
}

.italic {
font-style: italic;
}

.text-primary {
color: #2a5d5c;
}

.w-60 {
width: 15rem /* 240px */;
}

.bg-accent {
background-color: #11b981;
}

@liZe liZe added the crash Problems preventing documents from being rendered label May 13, 2024
@liZe
Copy link
Member

liZe commented May 14, 2024

Simple sample to reproduce:

<div style="display: grid">
  <div style="margin: auto">
  </div>
</div>

liZe added a commit that referenced this issue May 14, 2024
Auto margins are not handled (there already was a TODO for this), but at least
it doesn’t crash anymore.

Fix #2154.
@liZe liZe closed this as completed in 27a17b6 May 14, 2024
@liZe
Copy link
Member

liZe commented May 14, 2024

This bug should now be fixed, feedback is welcome!

@Zerotask
Copy link
Author

Thank you for your work. I just tried it with version 62.1 e00e393 and it works now - don't get any errors.

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