Fix update_index throwing AttributeError when value is None (#5757)

pull/5764/head
Ascani Carlo 2020-01-09 17:53:09 +01:00 zatwierdzone przez Matt Westcott
rodzic c4a0ec2c4f
commit 4864920555
4 zmienionych plików z 24 dodań i 3 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ Changelog
* Fix: `file_size` and `file_hash` not updated when Document file changed (Andreas Bernacca)
* Fix: Fixed order of URLs in project template so that static / media URLs are not blocked (Nick Smith)
* Fix: Added verbose_name_plural for form submission model (Janneke Janssen)
* Fix: Prevent `update_index` failures and incorrect front-end rendering on blank `TableBlock` (Carlo Ascani)
2.7.1 (08.01.2020)

Wyświetl plik

@ -59,6 +59,7 @@ Bug fixes
* ``file_size`` and ``file_hash`` not updated when Document file changed (Andreas Bernacca)
* Fixed order of URLs in project template so that static / media URLs are not blocked (Nick Smith)
* Added verbose_name_plural for form submission model (Janneke Janssen)
* Prevent ``update_index`` failures and incorrect front-end rendering on blank ``TableBlock`` (Carlo Ascani)
Upgrade considerations

Wyświetl plik

@ -83,8 +83,9 @@ class TableBlock(FieldBlock):
def get_searchable_content(self, value):
content = []
for row in value.get('data', []):
content.extend([v for v in row if v])
if value:
for row in value.get('data', []):
content.extend([v for v in row if v])
return content
def render(self, value, context=None):
@ -116,7 +117,7 @@ class TableBlock(FieldBlock):
return render_to_string(template, new_context)
else:
return self.render_basic(value, context=context)
return self.render_basic(value or "", context=context)
@property
def media(self):

Wyświetl plik

@ -224,6 +224,12 @@ class TestTableBlock(TestCase):
content = block.get_searchable_content(value)
self.assertEqual(content, ['Test 1', 'Test 2', 'Test 3', 'Bar', 'Foo', ])
def test_searchable_content_for_null_block(self):
value = None
block = TableBlock()
content = block.get_searchable_content(value)
self.assertEqual(content, [])
def test_render_with_extra_context(self):
"""
Test that extra context variables passed in block.render are passed through
@ -264,6 +270,18 @@ class TestTableBlock(TestCase):
self.assertHTMLEqual(result, expected)
self.assertIn('Test 2', result)
def test_empty_table_block_is_not_rendered(self):
"""
Test an empty table is not rendered.
"""
value = None
block = TableBlock()
result = block.render(value)
expected = ''
self.assertHTMLEqual(result, expected)
self.assertNotIn('None', result)
class TestTableBlockForm(WagtailTestUtils, SimpleTestCase):