Skip to content

Commit 8d2e7c0

Browse files
authored
fix: Fix KeyError in isd_to_elements (#876)
1 parent 24ebd0f commit 8d2e7c0

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
### Fixes
8+
* Fix KeyError when `isd_to_elements` doesn't find a type
89

910
### BREAKING CHANGES
1011

test_unstructured/staging/test_base_staging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_isd_to_elements():
4646
{"text": "Blurb2", "type": "Title"},
4747
{"text": "Blurb3", "type": "ListItem"},
4848
{"text": "Blurb4", "type": "BulletedText"},
49+
{"text": "No Type"},
4950
]
5051

5152
elements = base.isd_to_elements(isd)

unstructured/staging/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def isd_to_elements(isd: List[Dict[str, Any]]) -> List[Element]:
7676
if _metadata_dict is not None:
7777
metadata = ElementMetadata.from_dict(_metadata_dict)
7878

79-
if item["type"] in TYPE_TO_TEXT_ELEMENT_MAP:
79+
if item.get("type") in TYPE_TO_TEXT_ELEMENT_MAP:
8080
_text_class = TYPE_TO_TEXT_ELEMENT_MAP[item["type"]]
8181
elements.append(
8282
_text_class(
@@ -85,7 +85,7 @@ def isd_to_elements(isd: List[Dict[str, Any]]) -> List[Element]:
8585
metadata=metadata,
8686
),
8787
)
88-
elif item["type"] == "CheckBox":
88+
elif item.get("type") == "CheckBox":
8989
elements.append(
9090
CheckBox(
9191
checked=item["checked"],

0 commit comments

Comments
 (0)