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

'PendingProperty' object is not subscriptable #2075

Closed
alejandro-perez opened this issue Feb 15, 2024 · 8 comments
Closed

'PendingProperty' object is not subscriptable #2075

alejandro-perez opened this issue Feb 15, 2024 · 8 comments
Labels
crash Problems preventing documents from being rendered

Comments

@alejandro-perez
Copy link

When using weasyprint 61.0 I'm getting the above error in line

stream.set_color_rgb(*textbox.style['color'][:3])

I've added a dumb print line print(textbox.style["color"]) before that line, and this is what it shows:

 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.0, green=0.5215686274509804, blue=0.49019607843137253, alpha=1.0)
 RGBA(red=0.0, green=0.5215686274509804, blue=0.49019607843137253, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.5568627450980392, green=0.08235294117647059, blue=0.34509803921568627, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=0.12941176470588237, green=0.1450980392156863, blue=0.1607843137254902, alpha=1.0)
 RGBA(red=1.0, green=1.0, blue=1.0, alpha=1.0)
 RGBA(red=1.0, green=1.0, blue=1.0, alpha=1.0)
 RGBA(red=1.0, green=1.0, blue=1.0, alpha=1.0)
 <weasyprint.css.validation.properties.PendingProperty object at 0x7f582692a560>

This did not happen with 60.2.

@alejandro-perez
Copy link
Author

Full traceback (with the additional line!)

Traceback (most recent call last):
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "/home/alex/OneDrive/consultancy-portal/src/opportunities/views.py", line 2194, in rendered_content
    pdf_data = super().rendered_content
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/django_weasyprint/views.py", line 93, in rendered_content
    return document.write_pdf()
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/document.py", line 390, in write_pdf
    pdf = generate_pdf(self, target, zoom, **options)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/pdf/__init__.py", line 192, in generate_pdf
    page.paint(stream, scale)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/document.py", line 99, in paint
    draw_page(self._page_box, stream)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/draw.py", line 65, in draw_page
    draw_stacking_context(stream, stacking_context)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/draw.py", line 174, in draw_stacking_context
    draw_stacking_context(stream, child_context)
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/draw.py", line 167, in draw_stacking_context
    draw_inline_level(
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/draw.py", line 1028, in draw_inline_level
    draw_text(
  File "/home/alex/OneDrive/consultancy-portal/venv/lib/python3.10/site-packages/weasyprint/draw.py", line 1072, in draw_text
    stream.set_color_rgb(*textbox.style['color'][:3])
TypeError: 'PendingProperty' object is not subscriptable

@liZe
Copy link
Member

liZe commented Feb 15, 2024

Hi!

Could you please share the document (HTML+CSS) that caused this bug, so that we can more easily reproduce?

@liZe liZe added the crash Problems preventing documents from being rendered label Feb 15, 2024
@alejandro-perez
Copy link
Author

Unfortunately I can't in an straightforward way. But I'll disable all CSS assets one by one until I find the exact point of failure.
Then see if I can repilcate with a shareable set of files

@alejandro-perez
Copy link
Author

Good news, I've found an offending example that I can share.

<!DOCTYPE html>
<html lang="en-GB">
<head>
    {% block head %}
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    {% endblock %}
</head>

<style>
    .bg-jsl {
        background-color: #00857d !important;
    }

    .text-white {
        color: white !important;
    }
</style>

<body>

<table class="table border-secondary border-top">
    <tr>
        <td class="fw-bold text-white bg-jsl" colspan="2">
            This works
        </td>
        <td class="fw-bold text-white bg-jsl">
            This works
        </td>
        <td class="border border-top bg-white">
            This fails
        </td>
    </tr>
</table>

</body>

</html>

This worked just fine with 60.2 but fails with 61.0. I just noticed that if I add text-black to the last <td> element's class list it works.

        <td class="border border-top text-black bg-white">
            This fails
        </td>

Also noticed that 61 does not need me to override .text-white as it works better with bootstrap.

@liZe liZe closed this as completed in 9405a84 Feb 16, 2024
@liZe
Copy link
Member

liZe commented Feb 16, 2024

It’s now fixed and tested.

Bootstrap uses a lot of variables in quite complicated ways, and version 61.0 should change (improve?) many subtle things with it. If you have some real-life feedback about Bootstrap in WeasyPrint, don’t hesitate to send a mail!

@alejandro-perez
Copy link
Author

Bootstrap uses a lot of variables in quite complicated ways

I realised that before 61 I needed to redefine things like .text-white whereas it does not seem to be needed with 61.

If you have some real-life feedback about Bootstrap in WeasyPrint, don’t hesitate to send a mail!

Will do many thanks. The reason why I'm using bootstrap is because I also use it to render a customer-facing form. Then I render the web form with weasyprint so that they get a PDF copy. They could use the print functionality from the browser, but it does nto allow me to number pages, and other killing features weeasyprint has.

@alejandro-perez
Copy link
Author

I also guess this alone does not qualify for a 61.1 :D ?

@liZe
Copy link
Member

liZe commented Feb 16, 2024

I also guess this alone does not qualify for a 61.1 :D ?

We have at least one more annoying bug we have to fix before 61.1, but it will come soon!

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