Avoid A Server Error During Translation If Optional Fields Are None - #917
Open
dchukhin wants to merge 2 commits into
Open
Avoid A Server Error During Translation If Optional Fields Are None#917dchukhin wants to merge 2 commits into
dchukhin wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_blockhas ablock_valueofNone, 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 ofNone: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.