Skip to content

Commit

Permalink
Notion Fix Nested Properties (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 authored Oct 22, 2024
1 parent 914da2e commit eccec6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
49 changes: 30 additions & 19 deletions backend/danswer/connectors/notion/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,29 @@ def _recurse_properties(inner_dict: dict[str, Any]) -> str | None:
)

# 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 "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
if isinstance(inner_dict, str):
# For some objects the innermost value could just be a string, not sure what causes this
return inner_dict

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
Expand All @@ -268,7 +273,13 @@ def _recurse_properties(inner_dict: dict[str, Any]) -> str | None:
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:
Expand Down
4 changes: 0 additions & 4 deletions backend/scripts/dev_run_background_jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import argparse
import subprocess
import threading

Expand Down Expand Up @@ -135,7 +134,4 @@ def run_jobs() -> None:


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run background jobs.")
args = parser.parse_args()

run_jobs()

0 comments on commit eccec6a

Please sign in to comment.