mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-17 11:30:58 +02:00
Notion Recurse Empty Final Field (#2819)
This commit is contained in:
parent
11372aac8f
commit
c148fa5bfa
@ -216,17 +216,28 @@ class NotionConnector(LoadConnector, PollConnector):
|
|||||||
def _properties_to_str(properties: dict[str, Any]) -> str:
|
def _properties_to_str(properties: dict[str, Any]) -> str:
|
||||||
"""Converts Notion properties to a string"""
|
"""Converts Notion properties to a string"""
|
||||||
|
|
||||||
def _recurse_properties(inner_dict: dict[str, Any]) -> str:
|
def _recurse_properties(inner_dict: dict[str, Any]) -> str | None:
|
||||||
if not inner_dict:
|
|
||||||
# Edge case handling, should not happen
|
|
||||||
return "N/A"
|
|
||||||
|
|
||||||
while "type" in inner_dict:
|
while "type" in inner_dict:
|
||||||
type_name = inner_dict["type"]
|
type_name = inner_dict["type"]
|
||||||
inner_dict = inner_dict[type_name]
|
inner_dict = inner_dict[type_name]
|
||||||
|
|
||||||
|
# If the innermost layer is None, the value is not set
|
||||||
|
if not inner_dict:
|
||||||
|
return None
|
||||||
|
|
||||||
if isinstance(inner_dict, list):
|
if isinstance(inner_dict, list):
|
||||||
return ", ".join(
|
list_properties = [
|
||||||
[_recurse_properties(item) for item in inner_dict if item]
|
_recurse_properties(item) for item in inner_dict if item
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
", ".join(
|
||||||
|
[
|
||||||
|
list_property
|
||||||
|
for list_property in list_properties
|
||||||
|
if list_property
|
||||||
|
]
|
||||||
|
)
|
||||||
|
or None
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO there may be more types to handle here
|
# TODO there may be more types to handle here
|
||||||
@ -244,11 +255,13 @@ class NotionConnector(LoadConnector, PollConnector):
|
|||||||
return f"Until {end}"
|
return f"Until {end}"
|
||||||
|
|
||||||
if "id" in inner_dict:
|
if "id" in inner_dict:
|
||||||
logger.debug("Skipping Notion Id field")
|
# This is not useful to index, it's a reference to another Notion object
|
||||||
return "Unreadable Property"
|
# and this ID value in plaintext is useless outside of the Notion context
|
||||||
|
logger.debug("Skipping Notion object id field property")
|
||||||
|
return None
|
||||||
|
|
||||||
logger.debug(f"Unreadable property from innermost prop: {inner_dict}")
|
logger.debug(f"Unreadable property from innermost prop: {inner_dict}")
|
||||||
return "Unreadable Property"
|
return None
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
for prop_name, prop in properties.items():
|
for prop_name, prop in properties.items():
|
||||||
@ -258,7 +271,8 @@ class NotionConnector(LoadConnector, PollConnector):
|
|||||||
inner_value = _recurse_properties(prop)
|
inner_value = _recurse_properties(prop)
|
||||||
# Not a perfect way to format Notion database tables but there's no perfect representation
|
# Not a perfect way to format Notion database tables but there's no perfect representation
|
||||||
# since this must be represented as plaintext
|
# since this must be represented as plaintext
|
||||||
result += f"{prop_name}: {inner_value}\t"
|
if inner_value:
|
||||||
|
result += f"{prop_name}: {inner_value}\t"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user