Skip to content

Commit

Permalink
modified notion source to handle key error for "use_name" not provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
dat-a-man committed Aug 14, 2023
1 parent 2cc5fb3 commit 35f15e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sources/notion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def notion_databases(
]

for database in database_ids:
if "use_name" not in database:
# Fetch the database details from Notion
details = notion_client.get_database(database["id"])

# Extract the name/title from the details
# This depends on the structure of the response from Notion.
# Here, I'm assuming the title is stored similarly to your earlier logic.
database["use_name"] = details["title"][0]["plain_text"]

notion_database = NotionDatabase(database["id"], notion_client)
yield dlt.resource( # type: ignore
notion_database.query(),
Expand Down
11 changes: 11 additions & 0 deletions sources/notion/helpers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,14 @@ def search(
next_cursor = response.get("next_cursor")
has_more = next_cursor is not None
start_cursor = next_cursor

def get_database(self, database_id: str) -> Dict[str, Any]:
"""Fetches the details of a specific database by its ID.
Args:
database_id (str): The ID of the database to fetch.
Returns:
Dict[str, Any]: The details of the database.
"""
return self.fetch_resource("databases", database_id)

0 comments on commit 35f15e4

Please sign in to comment.