Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notion Empty Property Fix #2817

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backend/danswer/connectors/notion/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,18 @@ def _properties_to_str(properties: dict[str, Any]) -> str:
"""Converts Notion properties to a string"""

def _recurse_properties(inner_dict: dict[str, Any]) -> str:
if not inner_dict:
# Edge case handling, should not happen
return "N/A"

while "type" in inner_dict:
type_name = inner_dict["type"]
inner_dict = inner_dict[type_name]
if isinstance(inner_dict, list):
return ", ".join([_recurse_properties(item) for item in inner_dict])
return ", ".join(
[_recurse_properties(item) for item in inner_dict if item]
)

# TODO there may be more types to handle here
if "name" in inner_dict:
return inner_dict["name"]
Expand All @@ -245,6 +252,9 @@ def _recurse_properties(inner_dict: dict[str, Any]) -> str:

result = ""
for prop_name, prop in properties.items():
if not prop:
continue

inner_value = _recurse_properties(prop)
# Not a perfect way to format Notion database tables but there's no perfect representation
# since this must be represented as plaintext
Expand All @@ -268,13 +278,14 @@ def _read_pages_from_database(
text = self._properties_to_str(result.get("properties", {}))
if text:
result_blocks.append(NotionBlock(id=obj_id, text=text, prefix="\n"))

# Add nested pages/databases for further processing as separate documents
if obj_type == "page":
logger.debug(
f"Found page with ID '{obj_id}' in database '{database_id}'"
)
result_pages.append(result["id"])
elif obj_type == "database":
# TODO add block for database
logger.debug(
f"Found database with ID '{obj_id}' in database '{database_id}'"
)
Expand Down