fix(notion): parent pages to data_source_id for API 2025-09-03 (RCA-33)#8
Conversation
The Notion write-out seam never actually wrote: notion-client 3.1.0
pins API version 2025-09-03, which split databases into databases +
data sources. `_ensure_node_page` parented page creation with
`{"database_id": <id>}`, but the configured NOTION_WIKI_DB_ID is a
data-source id — so every `pages.create` 404'd with ObjectNotFound
and the integration silently failed.
Parent with `{"type": "data_source_id", "data_source_id": ...}` instead,
which keeps the configured env value as-is. Verified live end-to-end via
the production `sync_node_to_notion` path against the real workspace.
- test_kb_notion.py: pin the parent shape so a regression to the legacy
database_id parent fails in CI instead of silently at runtime (the
mocked suite never validated the parent, which is why this slipped).
- scripts/notion_smoke.py: reusable 3-stage live connectivity check
(token / data-source reachable / real write), --write and --keep flags.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughSwitch Notion page creation to use the ChangesNotion parent field migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/notion_smoke.py`:
- Around line 4-8: The docstring's staged diagnostic description is wrong: it
calls out "databases.retrieve(db_id)" for stage 2 but the code actually queries
the data_sources endpoint (data_sources/{id}); update the docstring in
scripts.notion_smoke.py so stage 2 describes the actual call (e.g.,
"data_sources.retrieve(data_source_id)" or "GET data_sources/{id} — data source
reachable & integration shared") to match the request performed on lines that
hit data_sources/{id}.
- Around line 42-44: Replace the brittle raw request call to the Notion SDK with
the typed helper: instead of await
client.request(path=f"data_sources/{settings.NOTION_WIKI_DB_ID}", method="GET")
use await
client.data_sources.retrieve(data_source_id=settings.NOTION_WIKI_DB_ID"); update
the same pattern found at the other occurrence (around line ~117) as well; leave
the existing await client.aclose() in finally as-is since AsyncClient in this
repo's pinned notion-client (3.1.0) supports an awaitable aclose().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 511e662a-42af-4d82-91e6-5538a9465f2a
📒 Files selected for processing (3)
app/services/kb/notion.pyscripts/notion_smoke.pytests/test_kb_notion.py
PR #8 review autofixes: - pyproject: notion-client>=2.2 -> >=3.1. The data_source_id parent shape requires Notion API 2025-09-03, only sent by notion-client 3.x. A 2.x resolve would send the legacy database_id parent and 404, reintroducing the exact silent ObjectNotFound break PR #8 fixes. Refresh uv.lock. - scripts/notion_smoke.py: stage 2 now uses the typed client.data_sources.retrieve(...) instead of a raw client.request(...), fix the docstring (stage 2 was mislabeled databases.retrieve), add a docstring to main() (docstring-coverage gate), and drop a redundant truthiness guard in the --keep branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
RCA-33 asked: does the Notion integration even write on the backend? It did not. Testing it live surfaced a silent break, now fixed.
Root cause
notion-client3.1.0 pins Notion API2025-09-03, which split databases → data sources. The write seam (app/services/kb/notion.py) parented page creation with{"database_id": <id>}, but the configuredNOTION_WIKI_DB_IDis a data-source id → everypages.createreturnedObjectNotFound. Nothing was ever written.The mocked unit suite passed all along because it never validated the
parentshape — the bug only existed against the live API.Fix
app/services/kb/notion.py: parent with{"type": "data_source_id", "data_source_id": notion_wiki_db_id}— keeps the configured env value as-is.tests/test_kb_notion.py: regression test pins the parent shape so a revert to the legacydatabase_idfails in CI.scripts/notion_smoke.py: reusable 3-stage live connectivity check (token / data-source reachable / real write),--writeand--keepflags.Verification
Live end-to-end through the production
sync_node_to_notionpath against the real workspace: page created inCoursesdata source for node "BB: Biological and Biochemical Foundations of Living Systems" + fact bullet, repeatable across runs. Mocked suite: 14 passed, lint clean.Unblocks RCA-14 child #2 (coarser node-page Notion sync).
Closes RCA-33.
🤖 Generated with Claude Code
Summary by CodeRabbit
Updates
New Features
Tests