Files
Sasha Rakhmatulin a70d39d30b fix: slug field stores an empty string on create, colliding on the unique index
`generateSlug`'s two operation branches disagreed on how to represent "no
slug yet". The create branch assigned `slugify(...)` unconditionally, so a
draft created before a title exists stored `''` — the admin submits
`title: ''`, and `slugify('')` returns `''`. The update branch already
falls back to `null` for the same case.

A unique index permits many missing values but only one `''`, and draft
saves skip field validation, so `required: true` does not catch it. The
first title-less draft inserted and the second failed with a duplicate key
error, which the admin surfaced as a blank Create New screen. Creating an
empty draft and typing the title afterwards is the default admin flow, so
this was the common path rather than an edge case.

The create branch now leaves an empty slug unset. `undefined` rather than
`null` matches what the unique index skips on both databases: Mongo's index
is sparse once drafts are enabled, and Postgres maps a missing value to
NULL. Storing `null` would have fixed Postgres alone while leaving Mongo
colliding on two nulls.

Adds a `slug-field-autosave` test collection and integration tests covering
a source-less draft, an empty source value, a custom slugify that returns
an empty string, and two source-less drafts coexisting under the unique
index. Verified against MongoDB, Postgres, and SQLite.
2026-09-09 17:20:23 +01:00
..
2024-11-11 13:59:05 -05:00