Skip to content

fix(core): search across all collections fails when one has no title field (#1178)#1550

Open
marcusbellamyshaw-cell wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1178-search-titleless-collections
Open

fix(core): search across all collections fails when one has no title field (#1178)#1550
marcusbellamyshaw-cell wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1178-search-titleless-collections

Conversation

@marcusbellamyshaw-cell

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the search API and MCP search tool throwing D1_ERROR: no such column: c.title when searching across all collections (no collections filter) and any search-enabled collection has no title field.

title is an optional user-defined field, not a system column on ec_* tables (the system columns are id, slug, status, author_id, primary_byline_id, created_at, updated_at, published_at, scheduled_at, deleted_at, version, live_revision_id, draft_revision_id, locale, translation_group). searchSingleCollection and getSuggestions selected c.title unconditionally, so the cross-collection path errored whenever it reached a collection without a title field. Passing an explicit collections list that happened to have titles masked the bug — which matches the report (works with ["pages","posts"], fails without collections).

The codebase already handles this exact gotcha in api/handlers/dashboard.ts (fetchRecentItems checks _emdash_fields for a title field and falls back to slug); this PR applies the same precedent to search.

Changes

  • Add FTSManager.hasTitleColumn(slug) — checks _emdash_fields for a title field (mirrors the dashboard handler).
  • searchSingleCollection: select NULL as title when the collection has no title column (results keep their slug; SearchResult.title is already optional).
  • getSuggestions: skip collections without a title field (a Suggestion.title is required and the query already filters on c.title IS NOT NULL, so these collections contribute nothing anyway).
  • Regression test reproducing the reported error across the searchWithDb and getSuggestions "all collections" paths.

Closes #1178

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes (oxlint, 0 diagnostics on changed files)
  • pnpm test passes (targeted: all search/MCP-search/suggest/i18n/schema suites — 138 tests green, incl. the new regression test)
  • pnpm format has been run (tabs; consistent with surrounding code)
  • I have added/updated tests for my changes
  • User-visible strings in the admin UI are wrapped for translation — n/a (no admin UI strings; server-side error codes only)
  • I have added a changeset (emdash patch)
  • New features link to an approved Discussion — n/a (bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 (Claude Code)

Screenshots / test output

Before (new test on the unpatched tree):

× searches across all collections when one lacks a title field
× returns suggestions across all collections, skipping ones without a title
  SqliteError: no such column: c.title
    ❯ searchSingleCollection src/search/query.ts:220
    ❯ getSuggestions src/search/query.ts:360

After:

Test Files  1 passed (1)
     Tests  2 passed (2)

…eld (emdash-cms#1178)

`title` is an optional user-defined field, not a system column on `ec_*`
tables. `searchSingleCollection` and `getSuggestions` selected `c.title`
unconditionally, so searching across all collections (no `collections`
filter) threw `D1_ERROR: no such column: c.title` whenever any
search-enabled collection lacked a `title` field. Scoping to collections
that happen to have a title masked the bug.

Add `FTSManager.hasTitleColumn` and use it to select `NULL` for the title
when the column is absent (results keep their slug) in
`searchSingleCollection`, and to skip title-less collections in
`getSuggestions` (a suggestion requires a title and the query already
filters on `c.title IS NOT NULL`).

Adds a regression test covering the cross-collection search and
suggestion paths with a collection that has no title field.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0b66374

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: search MCP tool returns D1_ERROR: no such column: c.title when collections argument is omitted

1 participant