Skip to content

fix: normalize None text to empty string in Text elements - #4463

Open
TrueFurina wants to merge 2 commits into
Unstructured-IO:mainfrom
TrueFurina:fix/image-none-text-str
Open

fix: normalize None text to empty string in Text elements#4463
TrueFurina wants to merge 2 commits into
Unstructured-IO:mainfrom
TrueFurina:fix/image-none-text-str

Conversation

@TrueFurina

@TrueFurina TrueFurina commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Fixes #4084: when an Image element is created with text=None (e.g. yolox hi-res model detects a bbox with missing text), str(element) returned a non-string, breaking printing/accessing the element.

Changes

  • unstructured/documents/elements.py:
    • Text.__init__: normalize None text to "" so self.text is always a str
    • Text.__str__: fall back to "" when self.text is None (defensive, e.g. deserialized elements)
  • test_unstructured/documents/test_elements.py: add test_Image_text_none_str_returns_empty_string covering both image.text == "" and str(image) == ""

Verification

  • ast.parse passes on both files
  • Local assertions: Image(text=None)text='' and str=''; Image(text='hello') unchanged → text='hello', str='hello'
  • Docs-only class hierarchy: Image(Text), no other behavior changed

Review in cubic

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.

bug/None text attribute when normalizing Picture to Image element

1 participant