Skip to content

Commit 5e85748

Browse files
Fix callouts with FileIcons (#504) [full CI check] (#506)
## NOTE: In order to fully test this user's contribution I had to merge the changes to a non-main branch first. This PR is only for testing the full CI flow + bumping version and changelog. Fix: #503 User: **I have tested this chang on my own fork of `unstructured-ingest` that I use for processing our customer data. It includes this fix and many other bug fixes that I would like to merge in!** --------- Co-authored-by: Teddy Wahle <[email protected]>
1 parent 0787bc6 commit 5e85748

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.26
2+
3+
* **Fix Notion connector error with FileIcons**
4+
15
## 1.0.25
26

37
* **Fix Notion user text and html getters**

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.25" # pragma: no cover
1+
__version__ = "1.0.26" # pragma: no cover

unstructured_ingest/processes/connectors/notion/types/blocks/callout.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,57 @@ def get_html(self) -> Optional[HtmlTag]:
5151
return None
5252

5353

54+
@dataclass
55+
class FileIconContent(FromJSONMixin):
56+
url: str
57+
expiry_time: Optional[str] = None # Add expiry_time if needed
58+
59+
@classmethod
60+
def from_dict(cls, data: dict):
61+
# Only include expiry_time if it exists in the dictionary
62+
# Notion API might not always include it
63+
init_data = {"url": data.get("url")}
64+
if "expiry_time" in data:
65+
init_data["expiry_time"] = data.get("expiry_time")
66+
return cls(**init_data)
67+
68+
69+
@dataclass
70+
class FileIcon(FromJSONMixin, GetHTMLMixin):
71+
file: FileIconContent
72+
type: str = "file"
73+
74+
@classmethod
75+
def from_dict(cls, data: dict):
76+
return cls(file=FileIconContent.from_dict(data=data.pop("file")), **data)
77+
78+
def get_html(self) -> Optional[HtmlTag]:
79+
# Render the file URL, similar to how ExternalIcon is handled
80+
if self.file:
81+
# Could potentially render an <img> tag, but sticking to URL for consistency
82+
return A([Href(self.file.url)], [f"[File Icon: {self.file.url}]"])
83+
else:
84+
return None
85+
86+
5487
class Icon(FromJSONMixin):
5588
@classmethod
56-
def from_dict(cls, data: dict) -> Union[EmojiIcon, ExternalIcon]:
89+
def from_dict(cls, data: dict) -> Union[EmojiIcon, ExternalIcon, FileIcon]:
5790
t = data.get("type")
5891
if t == "emoji":
5992
return EmojiIcon.from_dict(data)
6093
elif t == "external":
6194
return ExternalIcon.from_dict(data)
95+
elif t == "file":
96+
return FileIcon.from_dict(data)
6297
else:
6398
raise ValueError(f"Unexpected icon type: {t} ({data})")
6499

65100

66101
@dataclass
67102
class Callout(BlockBase):
68103
color: str
69-
icon: Optional[Union[EmojiIcon, ExternalIcon]] = None
104+
icon: Optional[Union[EmojiIcon, ExternalIcon, FileIcon]] = None
70105
rich_text: List[RichText] = field(default_factory=list)
71106

72107
@staticmethod
@@ -76,9 +111,11 @@ def can_have_children() -> bool:
76111
@classmethod
77112
def from_dict(cls, data: dict):
78113
rich_text = data.pop("rich_text", [])
114+
icon_data = data.pop("icon", None)
115+
icon = Icon.from_dict(icon_data) if icon_data else None
79116
return cls(
80117
color=data["color"],
81-
icon=Icon.from_dict(data.pop("icon")),
118+
icon=icon,
82119
rich_text=[RichText.from_dict(rt) for rt in rich_text],
83120
)
84121

0 commit comments

Comments
 (0)