Repository navigation
fix(fields): a blank slug is NULL on an unpublished page, '' on the home page, refused elsewhere - #1041
Conversation
`pages` autosaves, so the admin Create view saves an empty draft on the server before it redirects to it. Our slugify wrapper answered `''` for a blank title, and `pages.slug` carries a unique index: Postgres admits any number of NULLs under one but only a single `''`. One row holding `''` — the Home Page — therefore refused every later Create, and the view rendered its chrome with no body. No Page has been created since 2026-06-18. Payload's own default slugify returns `undefined` for a blank source for exactly this reason, so the wrapper now falls back to it. `slugifyValue` still answers `''`, which the Atlas region seeder relies on for its `||` fallback. The migration clears the rows written before this. It sweeps `_pages_v` too: restoring a version whose slug is `''` would write that value back onto the row and re-arm the collision. Refs #1038 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZ6TUnympp7DH2V1gj
The first pass answered `undefined` whenever the slugified result was blank, which is stricter than Payload's own default and stricter than #1038 needs. A name like `東京` slugifies to `''` under any rule, and `authors`, `song_tags`, `user_choices` and `regions` all declare `slug` NOT NULL — so that row stopped being written at all and surfaced as a raw DrizzleQueryError rather than the (wrong, but saved) row it stores today. Reproduced in the integration lane before and after. A blank *source* is the #1038 case and still answers `undefined`. That is exact parity with Payload's default, and a unit spec pins both directions: each half fails against the version it is there to catch. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZ6TUnympp7DH2V1gj
|
🚅 Deployed to the SahajCloud-pr-1041 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the right size for #1038: one line of behaviour, one data migration, two specs. It improves on the ticket — slugifyValue(x) || undefined would have nulled 東京 and broken the four NOT NULL collections, and commit 2 narrows it. The four doc edits are the spec count tests/PERF.md pins, so nothing is smuggled.
What does not hold up is the reasoning shipped as comments. Three claims are wrong or name the wrong guard, two of them in a migration and a field comment — the only record of why four collections were left alone. The behaviour is right; the explanation a reader inherits is not.
For #1040, not here: in authors, song_tags and user_choices the generator still answers '' for a source that transliterates to nothing, the uniqueness validate early-returns on it, and the second such row is a 5xx. Only option C's cost names this.
Findings
- should-fix —
slugField.ts:78: "exactly Payload's own default" is false for an empty-string source, the case the fix turns on. - should-fix —
20261027_190500_pages_blank_slug_to_null.ts:14: drafts are not what lets''land, and NOT NULL does not stop''. - consider —
slugField.ts:83: re-argues a rejected alternative already in the PR body.
What was checked
- #1038 vs the diff: all four criteria met. Step 2's
''-row check is the gap. slugField.tswhole, plus Pages, Authors, SongTags, UserChoices,nonEmptySlug.ts.- Snapshot:
pages.slugnullable + unique,_pages_v.version_slugnullable non-unique, the other four NOT NULL + unique — the only slug-bearing tables, and slug is unlocalized. - The
.jsonis byte-identical to20261027_000341's. - Payload's
generateSlug.js: create ignores the checkbox, so the source'srequiredguards. - Both
## Previewlinks answer 200; noPREVIEW_ADMIN_EMAIL, so no sign-in.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The slugify comment claimed exact parity with Payload's own default. It is not parity for the case #1038 turns on: `payload/dist/utilities/slugify.js` is `val?.trim()…`, so an empty-string source answers `''` there and `undefined` here. Optional chaining short-circuits on nullish alone. State what the override actually does — `undefined` for both nullish and blank, Payload's `''` kept where a source merely transliterates to nothing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVbC1PaTcTQJfidrq3
The comment said drafts are what skip "the field's own `required`". They are not: `slugField` installs a uniqueness `validate` on all five slug collections, and supplying one replaces Payload's default — the validator that enforces `required`. `src/collections/Regions/nonEmptySlug.ts` already documents that hole. What keeps `''` out of authors, song_tags and user_choices is the SOURCE field's `required`, which the factory never replaces, and drafts are the one path past it. NOT NULL does not refuse `''` either, so a blank there would be a row to fix rather than one that cannot exist. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVbC1PaTcTQJfidrq3
Why the rule is not in `slugifyValue` re-argues an alternative nobody reading the file fresh is weighing — change context, which belongs in the commit message and the PR body, both of which already carry it. The ⚠ block above keeps the load-bearing fact. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVbC1PaTcTQJfidrq3
|
Three critic threads, all adopted. Comments only — no behaviour changed, and the lean gate is green on 04ff8cb (234 files / 2958 tests).
The PR body carried the first two errors too, in 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
@sydevs-bot Revise. Could we simplify things if we simply reject blank slugs? |
Review findings on the home-page commit: - "Published" was judged in the request's locale only, but the slug is not localized. A non-draft `de` write that cleared the slug of a page live in `en` stored NULL and took the `en` URL with it. A page now counts as published if any locale is. - Nothing pinned the home page with `generateSlug` on, which is the column default. A case does now. - The home read selects `homePage` only, and the contract is explained once, in `src/globals/AGENTS.md`, which now says nothing moves `''` when `homePage` changes. - The regions comment drops a two-month-old row count and points at the audit script. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production holds 0 of 646 regions with a blank slug, read through the Atlas client key. The exception that let a stored `''` re-save unchanged, kept for the nested-docs cascade, now protects nothing. Regions refuse every blank, as authors, song-tags and user-choices do, and `blankAllowed` has one caller: the home page. The cascade spec existed only for that exception, so it goes. The blank-slug spec now pins that a stored blank region slug is refused even when re-saved whole, which is what the cascade does to each descendant. The audit script still says what a blank region costs, and two comments lose a row count that is no longer true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ive" by the published row Review findings on #1041, fixed whatever the home-page decision: - **A live page could lose its slug through a newer draft.** The "published in any locale" check read `siblingDocWithLocales._status`, which on a drafts update is the latest version. A published page with a newer draft therefore read as unpublished, and clearing its slug stored NULL. Whether a page is live is now read from the published row (`draft: false`), inside the write's transaction on a locale-isolated copy of `req`. - **A titled page could be unable to publish.** Payload's generator stores `generateSlug: false` on a publish, on a posted slug, and once a draft passes two versions. A non-admin can reset neither that nor the slug, so an untitled draft given a title later was refused on publish. A page that is not yet live is now filled from a usable title, whatever the checkbox says. A live page's cleared slug, which is its public URL, is still refused in every locale and never renamed. The NOT NULL collections are not filled either. - **The migration could null a published page.** It now leaves a published non-home `''` as it is and names it in the log. The home row takes `''` only if no other row holds it, and is named in the log if it cannot. Replayed through `up()` on a scratch database in four shapes. - **The regions audit script states plainly** that production held none, and that a blank region refuses its next save, so every ancestor save then fails. The refusal message no longer suggests a source the document already has. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The session for this item did not finish after 3 attempts. I have stopped retrying. A mention ( 🤖 sydevs dispatcher |
…-draft-slug # Conflicts: # AGENTS.md # docs/rules/testing-reqs.md # tests/AGENTS.md # tests/PERF.md
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since this branch, a page can't be published without a slug, and the slug field refuses before title's own check runs, so the captured field path is `slug`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
''. The home page keeps'', an unpublished page gets NULL, and anything else is refused.pagesdrafts stop colliding under the unique index, so Create works again (fix(fields): an untitled draft gets slug '' and blocks every new Page #1038).slug: ''(Payload's own Generate button, or any REST/Local API write) is no longer stored (fix(fields): a posted blank slug is stored, not refused or nulled #1040).''slugspagesalready holds: the home page's stays, any other becomes NULL.Change outline
Flow — the slug-generation hooks, per write
The factory puts one hook on each side of Payload's own
generateSlug, the checkbox field'sbeforeChangehook. It judges the slug the generator leaves, rather than predicting it.slugField({ blankAllowed? }) src/fields/slugField.ts generateSlug checkbox → hooks.beforeChange + nullOnDrafts # collection has drafts and slug is blank → NULL + # (so autosave doesn't read '' vs a stored NULL as an override) …Payload's generateSlug # unchanged: fills slug from the source + settleBlank # slug still blank after generation: + blankAllowed(doc) → '' # pages: the wm-web-config home page + drafts, not yet live (published row, draft: false, any locale): + usable title → slugify(title) # whatever the generateSlug checkbox says + else, this write unpublished → NULL # untitled drafts; the column is nullable there + otherwise → ValidationError 400 on `slug` # a live page's URL is never renamed slugify: slugifyValue(valueToSlugify) # main's, unchanged (#1038's override is gone)What each collection now does with a blank:
Files — the regions-only validator folds into the factory
src/collections/Regions/ -├── nonEmptySlug.ts # withNonEmptySlug: refused a newly blank region slug, grandfathered a stored one └── Regions.ts # slugField(); the checkbox default-off override staysContract — the stored rows
Preview
Both links need a sign-in; the repo guide's Railway row covers it (
PREVIEW_ADMIN_EMAIL)./admin/collections/pages/<id>. Onmainthe second one renders the admin chrome with an empty body.mainit stores the blank.Data: not seeded, and none is needed. Both flows create their own rows.
previewUrl.seedis unset for this repo.Contract impact
WeMeditateWeb (read only here, no change needed):
where[slug][equals]=<homePage.slug>.''alone. I measured this over REST in the int lane: a NULL slug returns 0 docs,''returns the home page.''. The previous version of this PR turned it into NULL, which would silently have dropped/'s hreflang cluster.''kept,/,/:slugand the sitemap behave exactly as before. The contract is recorded insrc/globals/AGENTS.md.Migration
src/migrations/20261027_190500_pages_blank_slug_to_null.tspages.slugblank values only. No column, index or type changes, and no non-blank slug is touched.''becomes NULL.'', but only if no other row holds it.''), which already has the target shape._pages_vis left alone: restoring a version runs the same hooks.up()on a scratch Postgres in four shapes:'': the home page becomes'', the draft NULL.'': it is kept, and both warnings fire.down()is a no-op, because writing''back to more than one row would break the unique index.Test results
tscoversrc/,tscovertests/, 232 unit files / 2945 tests (after mergingmain)slug-field-posted-blank(20 cases)pagespages-localize-statuscollections-smokeregionsregion-canonical-urlregion-breadcrumb-url-backfillatlas-collectionsglobals-client-readswemeditateAppStatuscontent-index-blockwm-app-configapp-cards-for-audienceclient-query-validationrole-based-accessmanager-inviteschema-utilscleanup-orphaned-mediauser-choicesuser-choices-by-timingmeditation-songsapiseeds/tests/atlas-translations-importEach new assertion was first watched failing:
04ff8cb): the posted-blank and generated-blank cases fail. They store'', or a postednullreaches Postgres as aDrizzleQueryError.3190713): the five home-page and published-page cases fail. Those are the published refusal for''and fornull, the home page keeping''and turning a posted NULL into'', and an author's stored''being refused.dewrite cleared the slug of a page live inen.abe9a193: three cases fail. They are the regenerate-from-title case, "refuses clearing the slug of a live page through a newer draft" (the live check read the latest draft), and "publishes an untitled draft once titled, however many times it was saved" (a storedgenerateSlug: falseleft it refused).siblingDocWithLocalesagain fails the newer-draft case.Manual verification
PATCH /api/authors/<id>with{"slug":""}answers 400 onslug, not 5xx.POST /api/authorswith{"name":"Grounding Check"}answers 201 with a generated slug.GET /api/pages?where[slug][equals]=&trash=true&draft=truemust return exactly the home page. On WeMeditateWeb,/must still emit its hreflang alternates.Notes for reviewer
The home page keeps
'': option A, chosen by the owner over a real slug (e.g.home). A real slug would expose/homethrough the'/' + slugbuilders in both repos:webPath/webUrlwould advertise…/home. Live preview would load/home, which WeMeditateWeb 302s to/, dropping the preview token.origin/main:ROUTE_BUILDERS.pagesinlib/document-routes.ts,partitionPublishedPages, and the nav and footer builders render'/' + slug. So any rich-text link, card or nav entry that references the home document would link/home(a redirect), where today it is dropped.A page not yet live is filled from its title, whatever
generateSlugsays. Payload stores the checkboxfalseon a publish, on a posted slug, and once a draft passes two versions, and a non-admin can reset neither it nor the slug. A live page's cleared slug is refused instead, because renaming a live URL silently is worse.On "make
slugrequired so it refuses NULL, and give the home page the blank slug": built, with one finding that changes its shape.pages.slugis alreadyrequired: true. So the column itself cannot refuse NULL.The home page is identified by
wm-web-config.homePage. A blank-slugpageswrite reads that global once, withselect: { homePage: true }. Nothing moves''whenhomePagechanges: the new home page's blank is refused as "Value must be unique" until the old home page's slug is cleared or set. That is documented insrc/globals/AGENTS.md.A page published in any locale counts as published, because the slug is not localized. One consequence: an autosave that clears the slug of a published page is refused, not just its publish.
authors, song-tags and user-choices refuse every blank, a stored one included. That is the owner's ruling: production holds no such rows.
Regions refuse every blank too, a stored one included. Production holds 0 of 646 regions with a blank slug (read through the Atlas client key), so the cascade grandfather, and
region-blank-slug-cascadewhich existed only for it, are gone.scripts/audit-region-slugs.tsstays: a blank region would now refuse every save that cascades into it.withNonEmptySlugis deleted, although fix(fields): a posted blank slug is stored, not refused or nulled #1040 said to keep it. Its own message could never show, its one stricter case protected nothing, and its grandfathering is no longer needed.tests/unit/slug-field-blank-source.spec.tsis deleted with the slugify override it pinned. Thepagesint cases now hold its guarantee.One cost of throwing from a hook: it ends the save before Payload raises the other fields' collected errors. An
authorscreate with a blanknamereports only the slug, with a message that names the field it is generated from.fix(fields): a posted blank slug is stored, not refused or nulled #1040's ⚠ about the validator and the generator seeing different data does not hold on 3.90.2.
beforeValidatefills every omitted field from the stored document before either runs.Local review
Three fresh critic passes. Each was given the tickets and the diff, not the implementer's reasoning.
Pass 1, on a predictive-validator design. Findings adopted, which led to the redesign above:
東京) still stored''.generateSlug's rules and drifted from them: a rename with the checkbox on, and apagesdraft titled東京.Pass 2, on the after-generation hooks. Adopted:
.mapwrapper.nullthrough to a 5xx.withNonEmptySlug.Pass 3, on the home-page design. Adopted:
dewrite cleared the slug of a page live inen. It now counts any locale, and a case pins it.generateSlugon (the column default) was untested. Now pinned.homePageonly.src/globals/AGENTS.md, with thehomePage-move caveat.Pass 4, on the review's design-independent fixes. Adopted:
localeIsolatedReq(req), withtrash: true.Dismissed, with reasons:
''.Detail
Why the judgement sits after the generator, not in the slug field's
validate. The slug's validator and the checkbox'sgenerateSlughook are separate promises in onePromise.all(payload/dist/fields/hooks/beforeChange/traverseFields.js). On 3.90.2 the validator reads the slug before the generator writes it. A validator therefore has to predict the generator, and that prediction drifts:東京, a rename with the checkbox on, and autosave's override rule all broke one. A field's own hooks run in sequence, so a hook placed aftergenerateSlugon the same field sees exactly what will be written.Why NULL only on an unpublished
pagesdraft. Payload's postgres adapter drops NOT NULL on every column of a collection with drafts (disableNotNull: !!collection.versions?.drafts), and draft saves skip validation. So that is the one place a NULL is storable and nothing else could refuse a blank. A published page has a public path to lose, so it is refused like any other collection.Why
nullOnDraftsalso runs before the generator.generateSlug's autosave branch treats a posted slug that differs from the stored one as the user's own override. A posted''against a stored NULL would then never regenerate from a title typed in the same save.Why the
_pages_vsweep went. Restoring a version runs these hooks, so a''in history is settled on the way back.version_slugcarries no unique index.Rows the NOT NULL collections may already hold. On
main, a source that transliterates to nothing (東京) could generate''inauthors,song_tagsanduser_choices. The owner confirmed production has none, so a stored''there is refused on its next save rather than grandfathered.Earlier review notes (#1038). Three reviewers suggested folding the second #1038
pagescase into the first. Kept separate: it pins that a titled draft still generates its slug. One reviewer readtests/AGENTS.md's "do not test slug generation" as covering these specs. That rule is about Payload's internals; these assert our own hooks' interaction with them.Closes #1038
Closes #1040
🤖 Generated with Claude Code