Wagtail: `update_index` throws `AttributeError` on TableBlock when value is `None`

Created on 19 Oct 2018  路  3Comments  路  Source: wagtail/wagtail

Found a bug? Please fill out the sections below. 馃憤

Issue Summary

update_index fails on StreamField TableBlock when its value is None, due to this line: https://github.com/wagtail/wagtail/blob/master/wagtail/contrib/table_block/blocks.py#L79

Throws AttributeError: 'NoneType' object has no attribute 'get'

Steps to Reproduce

  1. Add a StreamField to a page
  2. Add a TableBlock and leave it empty
  3. Publish the page
  4. Run python manage.py update_index, you will get a traceback leading to the above AttributeError

image

Technical details

Wagtail version: 2.2.2

Hacktoberfest Streamfield good first issue Bug

Most helpful comment

Fixed in #5757.

All 3 comments

Ran into same issue, so can confirm!

Also ran into this. Further, the empty TableBlock is rendered on-page as 'None', which is less serious but more complex to fix.
We've observed this in a draft page which even though more recent revisions had removed the empty block, still caused the overnight update_index job to fail.
Workaround to stop search indexing breaking:

_tableblock_get_searchable_content = TableBlock.get_searchable_content
def _safe_tableblock_get_searchable_content(self, value):
    if value is not None:
        return _tableblock_get_searchable_content(self, value)
    else:
        return []
TableBlock.get_searchable_content = _safe_tableblock_get_searchable_content

Fixed in #5757.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tmsndrs picture tmsndrs  路  3Comments

BertrandBordage picture BertrandBordage  路  3Comments

coredumperror picture coredumperror  路  3Comments

brylie picture brylie  路  3Comments

bmoe872 picture bmoe872  路  3Comments