Skip to content

Bug: ensure_section treats Notebook database ID as page parent (404 on new sections) #74

Description

@virtualguard101

Summary

Creating a new nav section directly under Notebook fails with Notion API 404 object_not_found because ensure_section passes the wiki database ID as a page ID.

Steps to reproduce

  1. Configure notion_sync with a wiki database (database_id / data_source_id).
  2. Add a new section under Notebook in .nav.yml (e.g. 音视频 with child notes).
  3. Run incremental or full sync for those notes.

Expected behavior

The tool creates the missing section page(s) under the Notebook wiki data source, then creates/updates child content pages.

Actual behavior

INFO create section 音视频 (Notebook/音视频)
ERROR FAIL obsidian/音视频/乐理基础.md: 404 object_not_found
message: Could not find page with ID: <database_id>

Other pages that already exist in .notion_sync_state.json still update successfully — this is not an integration permission problem.

Root cause

In mkdocs_note/utils/notion/sync.py, ensure_section:

  1. Resolves parent Notebook to state.root_page_id (the database ID) — correct.
  2. Sets parent_kind = "page" whenever item.parent_key is set — incorrect for Notebook.

create_page then sends {"parent": {"page_id": "<database_id>"}}, which Notion rejects.

resolve_parent_id already special-cases Notebook children to use data_source / database parent kinds; ensure_section does not.

Proposed fix

When the resolved parent is the Notebook root, use the same logic as resolve_parent_id:

parent_id = state.data_source_id or state.root_page_id
parent_kind = "data_source" if state.data_source_id else "database"

Apply this in ensure_section when parent_key points to Notebook (or when parent_id == state.root_page_id).

Acceptance criteria

  • New sections under Notebook are created without 404.
  • Top-level nav sections (e.g. Projects) continue to work.
  • Regression test covering ensure_section with Notebook parent.

Environment

  • mkdocs-note==3.3.0
  • Notion API 2025-09-03 (pages)

References

  • mkdocs_note/utils/notion/sync.pyensure_section, resolve_parent_id
  • mkdocs_note/utils/notion/client.pycreate_page

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions