Skip to content

Avoid A Server Error During Translation If Optional Fields Are None - #917

Open
dchukhin wants to merge 2 commits into
wagtail:mainfrom
dchukhin:fix-nonetype-bug
Open

Avoid A Server Error During Translation If Optional Fields Are None#917
dchukhin wants to merge 2 commits into
wagtail:mainfrom
dchukhin:fix-nonetype-bug

Conversation

@dchukhin

@dchukhin dchukhin commented Apr 14, 2026

Copy link
Copy Markdown

Fixes #875, though this is a wider fix than what was mentioned in #875.
Fixes #918.

Description

Problem

Currently, trying to translate a page with a blank optional field can cause a server error. To reproduce, I created a sample repo with an optional CharBlock, and when translating a page with the optional CharBlock, the server error is triggered.

Fix

This pull request adds a check for when StreamFieldSegmentExtractor.handle_block has a block_value of None, and simply returns [] in that case.
Tests have been added for different block types.

Question

One thing I want to make explicit here is that after implementing this change, translating the page does work 👏🏻 , but the translated page (in Wagtail) does not show the optional field (as if the field didn't exist). In the page's block's raw_data, I see that the optional field has a value of None:

[{'type': 'demo_block', 'value': {'required_text': 'This field has content', 'optional_text': None}, 'id': '45172f98-27d1-4780-8643-4f7248124f21'}]

To me this seems like a problem, but is it? Or is this the intended Wagtail behavior?
I started to explore what it may look like to make the field editable on the translated page, and it looks much more complex than this change. I'm ok with making that change, but want to make sure it's the direction that maintainers support.

AI usage

This pull request includes code written with the assistance of AI. This code was reviewed and verified by me.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Translation Fails When Optional CharBlock Is Empty Translation fails when EmbedBlock is empty

1 participant