Notion Fix Nested Properties (#2877)

This commit is contained in:
Yuhong Sun
2024-10-22 14:10:31 -07:00
committed by GitHub
parent 914da2e4cb
commit eccec6ab7c
2 changed files with 29 additions and 22 deletions

View File

@@ -241,24 +241,29 @@ class NotionConnector(LoadConnector, PollConnector):
)
# TODO there may be more types to handle here
if "name" in inner_dict:
return inner_dict["name"]
if "content" in inner_dict:
return inner_dict["content"]
start = inner_dict.get("start")
end = inner_dict.get("end")
if start is not None:
if end is not None:
return f"{start} - {end}"
return start
elif end is not None:
return f"Until {end}"
if isinstance(inner_dict, str):
# For some objects the innermost value could just be a string, not sure what causes this
return inner_dict
if "id" in inner_dict:
# This is not useful to index, it's a reference to another Notion object
# and this ID value in plaintext is useless outside of the Notion context
logger.debug("Skipping Notion object id field property")
return None
elif isinstance(inner_dict, dict):
if "name" in inner_dict:
return inner_dict["name"]
if "content" in inner_dict:
return inner_dict["content"]
start = inner_dict.get("start")
end = inner_dict.get("end")
if start is not None:
if end is not None:
return f"{start} - {end}"
return start
elif end is not None:
return f"Until {end}"
if "id" in inner_dict:
# This is not useful to index, it's a reference to another Notion object
# 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}")
return None
@@ -268,7 +273,13 @@ class NotionConnector(LoadConnector, PollConnector):
if not prop:
continue
inner_value = _recurse_properties(prop)
try:
inner_value = _recurse_properties(prop)
except Exception as e:
# This is not a critical failure, these properties are not the actual contents of the page
# more similar to metadata
logger.warning(f"Error recursing properties for {prop_name}: {e}")
continue
# Not a perfect way to format Notion database tables but there's no perfect representation
# since this must be represented as plaintext
if inner_value:

View File

@@ -1,4 +1,3 @@
import argparse
import subprocess
import threading
@@ -135,7 +134,4 @@ def run_jobs() -> None:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run background jobs.")
args = parser.parse_args()
run_jobs()