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

UnboundLocalError: local variable 'lower_guess' referenced before assignment #409

Closed
ghost opened this Issue Jan 9, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@ghost

ghost commented Jan 9, 2017

I have tried to convert some generated HTML file (the stripped version is
test.zip) and WeasyPrint 0.34 under Python 3.6.0 on Windows 7 throws the following exception:

WARNING: @font-face is currently not supported on Windows
WARNING: Ignored 'box-shadow: 0px 0px 3px #000' at 9:5, unknown property.
Traceback (most recent call last):
  File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\__main__.py", line 168, in <module>
    main()
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\__main__.py", line 164, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\__init__.py", line 180, in write_pdf
    presentational_hints=presentational_hints).write_pdf(
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\__init__.py", line 143, in render
    self, stylesheets, enable_hinting, presentational_hints)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\document.py", line 334, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\document.py", line 334, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\__init__.py", line 53, in layout_document
    pages = list(make_all_pages(context, root_box))
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\pages.py", line 567, in make_all_pages
    page_number)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\pages.py", line 513, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 42, in block_level_layout
    device_size, page_is_empty, absolute_boxes, fixed_boxes)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 364, in table_layout
    all_groups_layout()
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 351, in all_groups_layout
    skip_stack, position_y, max_position_y, page_is_empty)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 258, in body_groups_layout
    group, position_y, max_position_y, page_is_empty, skip_stack)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 129, in group_layout
    fixed_boxes=fixed_boxes)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\blocks.py", line 91, in block_box_layout
    context, box, (containing_block.width, containing_block.height))
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 740, in table_wrapper_width
    auto_table_layout(context, wrapper, containing_block)
  File "D:\Marek\Projekty\neklid.devel.py3\pdf\weasyprint\layout\tables.py", line 584, in auto_table_layout
    if upper_guess == lower_guess:
UnboundLocalError: local variable 'lower_guess' referenced before assignment

@liZe liZe added bug crash labels Jan 18, 2017

@Pilen

This comment has been minimized.

Show comment
Hide comment
@Pilen

Pilen Jan 23, 2017

I also got this error.

import weasyprint

test = """
<!DOCTYPE html>
<html>
  <head>
    <style>
      td {{
        width: 5mm;
        padding: 0mm;
      }}
    </style>
  </head>
  <body>
    <table>
      <tr>
        {}
      </tr>
    </table>
  </body>
</html>
""".format("<td>x</td>"*50)
weasyprint.HTML(string=test).write_pdf("test.pdf")

I get the following error:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    weasyprint.HTML(string=test).write_pdf("test.pdf")
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/__init__.py", line 180, in write_pdf
    presentational_hints=presentational_hints).write_pdf(
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/__init__.py", line 143, in render
    self, stylesheets, enable_hinting, presentational_hints)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/document.py", line 334, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/document.py", line 334, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/__init__.py", line 53, in layout_document
    pages = list(make_all_pages(context, root_box))
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/pages.py", line 567, in make_all_pages
    page_number)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/pages.py", line 513, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 91, in block_box_layout
    context, box, (containing_block.width, containing_block.height))
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/tables.py", line 740, in table_wrapper_width
    auto_table_layout(context, wrapper, containing_block)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/tables.py", line 584, in auto_table_layout
    if upper_guess == lower_guess:
UnboundLocalError: local variable 'lower_guess' referenced before assignment

But if I turn 50 into 49 or if i change padding to 1mm, or remove the width, then it works again.

I use Python 3.5.2 and WeasyPrint 0.34

Pilen commented Jan 23, 2017

I also got this error.

import weasyprint

test = """
<!DOCTYPE html>
<html>
  <head>
    <style>
      td {{
        width: 5mm;
        padding: 0mm;
      }}
    </style>
  </head>
  <body>
    <table>
      <tr>
        {}
      </tr>
    </table>
  </body>
</html>
""".format("<td>x</td>"*50)
weasyprint.HTML(string=test).write_pdf("test.pdf")

I get the following error:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    weasyprint.HTML(string=test).write_pdf("test.pdf")
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/__init__.py", line 180, in write_pdf
    presentational_hints=presentational_hints).write_pdf(
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/__init__.py", line 143, in render
    self, stylesheets, enable_hinting, presentational_hints)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/document.py", line 334, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/document.py", line 334, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/__init__.py", line 53, in layout_document
    pages = list(make_all_pages(context, root_box))
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/pages.py", line 567, in make_all_pages
    page_number)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/pages.py", line 513, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 97, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 599, in block_container_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 69, in block_level_layout
    adjoining_margins)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/blocks.py", line 91, in block_box_layout
    context, box, (containing_block.width, containing_block.height))
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/tables.py", line 740, in table_wrapper_width
    auto_table_layout(context, wrapper, containing_block)
  File "/home/pilen/code/xstitch/venv/lib/python3.5/site-packages/weasyprint/layout/tables.py", line 584, in auto_table_layout
    if upper_guess == lower_guess:
UnboundLocalError: local variable 'lower_guess' referenced before assignment

But if I turn 50 into 49 or if i change padding to 1mm, or remove the width, then it works again.

I use Python 3.5.2 and WeasyPrint 0.34

@dhiltonp

This comment has been minimized.

Show comment
Hide comment
@dhiltonp

dhiltonp Nov 13, 2017

Currently hitting this issue on Python 3.6.3 and WeasyPrint 0.41, with this file: https://pastebin.com/raw/QAuuneeF

guesses was unordered, with these values:
([67.7412109375, 186.90625], [67.7412109375, 186.90625], [67.7412109375, 186.90625], [67.7412109375, 119.90625])

It's defined as

 guesses = (
        min_content_guess, min_content_percentage_guess,
        min_content_specified_guess, max_content_guess)

so somehow max_content_guesses (column_max_content_widths[:]) is not the max_content_widths.

Explicitly calling guesses = sorted(guesses, key=lambda x: sum(x)) at tables.py:572 fixes the problem, but doesn't identify the root cause.

The trouble seems to stem from preferred.py:43 and 67; min_content_width and max_content_width.

dhiltonp commented Nov 13, 2017

Currently hitting this issue on Python 3.6.3 and WeasyPrint 0.41, with this file: https://pastebin.com/raw/QAuuneeF

guesses was unordered, with these values:
([67.7412109375, 186.90625], [67.7412109375, 186.90625], [67.7412109375, 186.90625], [67.7412109375, 119.90625])

It's defined as

 guesses = (
        min_content_guess, min_content_percentage_guess,
        min_content_specified_guess, max_content_guess)

so somehow max_content_guesses (column_max_content_widths[:]) is not the max_content_widths.

Explicitly calling guesses = sorted(guesses, key=lambda x: sum(x)) at tables.py:572 fixes the problem, but doesn't identify the root cause.

The trouble seems to stem from preferred.py:43 and 67; min_content_width and max_content_width.

@liZe liZe added this to the v0.42 milestone Nov 15, 2017

liZe added a commit that referenced this issue Nov 17, 2017

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Nov 17, 2017

Member

732db43 fixes the error reported by @Pilen but the other ones are probably different bugs. @dhiltonp I can't reproduce the bug with your sample, does this exact file raises the error for you (or maybe using anonymous data broke it)?

Member

liZe commented Nov 17, 2017

732db43 fixes the error reported by @Pilen but the other ones are probably different bugs. @dhiltonp I can't reproduce the bug with your sample, does this exact file raises the error for you (or maybe using anonymous data broke it)?

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Nov 17, 2017

Member

@Pilen I even think that 588203b fixed this issue. Could you try with the current git version?

Member

liZe commented Nov 17, 2017

@Pilen I even think that 588203b fixed this issue. Could you try with the current git version?

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Dec 4, 2017

Member

@ghost @Pilen I assume that this bug is solved now by 588203b and 732db43. Feel free to reopen with a broken example if you still get this issue.

Member

liZe commented Dec 4, 2017

@ghost @Pilen I assume that this bug is solved now by 588203b and 732db43. Feel free to reopen with a broken example if you still get this issue.

@liZe liZe closed this Dec 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment