`to_python` throws `AttributeError` on `TableBlock` when value is None
katdom13 opened this issue · comments
Issue Summary
Similar to: #4822
After upgrading one of our sites to 6.0, attempting to update some of our pages' indices results in a server error.
File "/venv/lib/python3.8/site-packages/wagtail/contrib/table_block/blocks.py", line 135, in to_python
if not value.get("table_header_choice", ""):
AttributeError: 'NoneType' object has no attribute 'get'
This is because, in Wagtail 6.0, the following code has been added:
fe1a306#diff-f058d7a36746222950f678ed6b178205778e4e1e5b85f0299c2a7c3b9d6c8939R129
Steps to Reproduce
- Create a page with an empty TableBlock in its body
- Before Wagtail 6.0, this should save and render OK
- After upgrading to 6.0, editing the same page will throw an error.
- Looking at the logs, you should see the error above
A workaround is to identify those pages and remove the empty TableBlocks, but this would prove to be a tedious task if there are many page instances.
A possible fix would be to check if the value is not None first:
if value and not value.get("table_header_choice", ""):
Thanks for the report! I can confirm this issue using the bakerydemo by creating a new Recipe page with an empty table block.
Thanks for the bug report and the quick fix @laymonage