Prevent crash when loading an empty table block in the editor

pull/11820/head
Sage Abdullah 2024-04-03 16:01:27 +07:00 zatwierdzone przez Matt Westcott
rodzic f941b45b58
commit cc819e9179
2 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -132,7 +132,7 @@ class TableBlock(FieldBlock):
value for the header choice. I would really like to have this default to "" and force the
editor to reaffirm they don't want any headers, but that would be a breaking change.
"""
if not value.get("table_header_choice", ""):
if value and not value.get("table_header_choice", ""):
if value.get("first_row_is_table_header", False) and value.get(
"first_col_is_header", False
):

Wyświetl plik

@ -439,6 +439,12 @@ class TestTableBlock(TestCase):
"""
self.assertHTMLEqual(result, expected)
def test_empty_table_block_to_python(self):
# Should not raise an error
# See https://github.com/wagtail/wagtail/issues/11816
block = TableBlock()
self.assertIsNone(block.to_python(None))
class TestTableBlockForm(WagtailTestUtils, SimpleTestCase):
def setUp(self):