Skip to content

fix(core): leave documents.namespace to its column default when a document has none - #1806

Merged
ajianaz merged 1 commit into
developfrom
fix/doc-create-namespace-not-null
Nov 26, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/doc-create-namespace-not-null

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

Creating a document no longer fails with NOT NULL constraint failed: documents.namespace on a store whose documents table still has namespace TEXT NOT NULL DEFAULT 'default'. The insert leaves the column out when the document names no namespace, so each kind of store applies its own default.

Why

Reported against v0.24.1: uteke doc create (insert document: missing required field), POST /doc/create (500) and uteke_doc_create all fail.

Cause: a store that went through schema v11 keeps namespace TEXT NOT NULL DEFAULT 'default' (migration v13 only drops the unique index and never rebuilds the table). Document::namespace is None for every document the engine writes, and the insert bound that None as an explicit NULL, so the column default never applied. The bind is the same in v0.22.1 through v0.24.1, so this is not a regression of 0.24.x; it hits stores that were created before documents became global (#614).

Not covered, by design: --namespace on doc create is still not a document scope. Documents are global since v13 (#614, #1271). A store created by this version has namespace TEXT DEFAULT NULL and keeps the column empty; an old store now stores 'default'.

The structural import (import_full) bound the same NULL and uses INSERT OR IGNORE, so on an old store it dropped such documents without an error. Fixed the same way.

How

Two insert statements in upsert_document_in: with the namespace column when doc.namespace is Some, without it when None. The structural import builds the column and ?5 slot conditionally and keeps the parameter list as it was. No schema migration: rebuilding documents would have to carry the FTS triggers, the chunk and room foreign keys and the self-reference of parent_id, and the insert fix covers old and new stores alike.

Testing

  • cargo test --workspace passes
  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • Cora review run locally (cora review --base origin/develop)
  • Manual smoke-test of the affected feature

Schema-migration-adjacent change, so the old shape is tested directly:

  • a_store_with_the_old_not_null_namespace_column_takes_a_new_document: a v11-shaped database migrated to the current version, then a document upsert. Failed before the fix with insert document: missing required field (the message of the report), passes after; the stored namespace is 'default'.
  • a_new_store_keeps_the_namespace_of_a_new_document_empty: a store created by this version still stores no namespace.
  • a_document_without_a_namespace_imports_into_the_old_not_null_column: structural import into a store with the old column. Checked red with the fix switched off, green with it.

Related Issues

Report: "doc create fails: NOT NULL constraint failed: documents.namespace (CLI, HTTP, MCP)" on v0.24.1. No GitHub issue number yet.

Checklist

  • Branch name follows convention (fix/, feat/, docs/, chore/, refactor/, test/, perf/, security/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

…ument has none

A store that went through schema v11 keeps `namespace TEXT NOT NULL DEFAULT
'default'` on documents (migration v13 only dropped the unique index). The
insert bound NULL to that column explicitly, so every doc create failed with
"NOT NULL constraint failed: documents.namespace" on the CLI, HTTP (500) and
MCP.

The column is now left out of the insert when the document names no
namespace: an old store stores 'default', a store created by this version
keeps the column empty (documents are global, #614). The structural import
had the same bind and, being INSERT OR IGNORE, skipped such documents without
an error; it is fixed the same way.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit d9dbe62 into develop Nov 26, 2026
18 checks passed
ajianaz added a commit that referenced this pull request Nov 26, 2026
Patch release: doc create on stores that went through schema v11 (#1806), the website build (#1813), the secret detector gap (#1794), list_pinned with schema v28 (#1804), dependency updates and the MCP Registry rename.

Pre-release mutation gate: 2 mutants, 1 missed (Uteke::list_pinned wrapper), killed by a new test.
@ajianaz ajianaz mentioned this pull request Nov 26, 2026
4 tasks done
ajianaz added a commit that referenced this pull request Nov 26, 2026
Patch release v0.24.2: doc create on stores that went through schema v11 (#1806), the website build (#1813), the secret detector gap (#1794, #1810, #1816), list_pinned with schema v28 (#1804), dependency updates and the MCP Registry rename. See the CHANGELOG entry [0.24.2].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant