Data UI Backlog

Update on a NULL timestamp dies with 22007 ("false")

Reported 2026-10-01 on the chores model: add a chore, edit it, save — "Database error 22007: invalid input syntax for type timestamp: \"false\"" (chore_completed_at, parameter $7). Root cause chain: NULL column → [] on the wire → json-to-plist nil → full-data respects the explicit nil → db-value passed it through → Postmodern binds Lisp nil as SQL FALSE. Not chores-specific: any user-declared nullable timestamp broke the update path; nullable text silently stored the string "false"; integer / real / uuid cleared-to-NULL 22P02'd the same way.

Three-part fix, per fix-chores-plan.org (implemented as planned, no deviations):

  1. Engine (lisp/backend.lisp): db-value maps nil → :null (real SQL NULL) for :text / :integer / :real / :uuid / :timestamp; :boolean keeps nil (legitimate false); :list / :password untouched. Read-path guard in the same file: nil-valued :eq / :ne filters now translate to is [not] null with no placeholder and no collected value, in both add-where-clause and measure-request-grain-filters (rollup grain filters) — a nil left to bind would be col = NULL, which never matches. lisp/predicates.lisp: nil / :null elements in :in / :not-in / :has-all lists are now a validation error (an in (NULL) element would silently match nothing; :eq nil stays legal — that is the is-null feature).
  2. Frontend (web/src/App.tsx): both submitForm payload paths filter formValues to keys present in formDef (hasOwnProperty, not in): the edit form seeds values from the whole /api/item record, and off-form keys (the [] echo of a NULL timestamp) must not ride along. On-form empty arrays (checkbox-list / image-list "clear all") still go out; empty strings stay dropped. npm run build run.
  3. Chores model (models/chores.lisp): completed / completed-at / completed-by off :update-form / :add-form (owned by the :complete button's :spawn, the single write path for closure), staying in :list-form as history; :sorted-at t → :sortable t on completed-at (unreal key — the list header now actually sorts the history column). Behavior change confirmed by Donnie up front: the Complete button is the only way to close a chore.

Tests: new tests/timestamp-null-update-tests.lisp (timestamp-null-suite, 15 checks on the spawn-test fixture — explicit-nil update, JSON [] round trip, text clear-to-NULL not "false", insert default still fills, :not-null nil still rejected, is [not] null single + placeholder-alignment cases, nil-element :in rejection), registered in data-ui.asd with run-timestamp-null-tests in tests/helpers.lisp (added to run-tests). Full run-tests: 1 pre-existing failure only — the generator pinned-demo-set pin lists shopping / recurring, both deleted from models/ before this work (unrelated; e7b2817 removed them, the pin test was never updated).

Verified live on the dev chores instance: the exact original failing payload (whole-record echo with "completed-at": [] and "completed-by": ["admin"]) now succeeds and preserves NULL; the Complete button closes the row (timestamp + completed-by stamped, successor spawned with notes cleared); update-form no longer offers the spawn-owned fields; repro rows cleaned up. Docs: docs/model-reference.md filter-operator paragraph (nil elements rejected; :eq / :ne nil is is-null) and Known gaps #8 (clear-to-NULL now implemented for nullable scalar columns; write-through inherits it for its :value column only). Reported 2026-10-01 on the chores model: add a chore, edit it, save — "Database error 22007: invalid input syntax for type timestamp: \"false\"", unnamed portal parameter $7 (chore_completed_at). Not chores-specific: any user-declared nullable timestamp breaks the update path. Chain: NULL column → [] on the wire → json-to-plist nil → full-data respects the explicit nil → db-value :timestamp passes it through → Postmodern binds Lisp nil as SQL FALSE. Insert survives only via its default fallback; update has none.

Three-part fix: (1) db-value maps nil → :null for the scalar cases (:timestamp loud 22007 today; :text silently stores "false"); (2) App.tsx stops echoing [] for non-checkbox-list fields (the JSON form of NULL) on both submit paths; (3) the chores model takes completed / completed-at / completed-by off :update-form / :add-form — they are owned by the :complete :spawn (the single write path for closure), stay in the list as history; also :sorted-at t → :sortable t on completed-at (unreal key today). Model edit alone doesn't fix the 22007 (the edit form echoes the whole record, fields render or not).

Plan: fix-chores-plan.org.

Slot
1000
Status
60 Done
Tags
mvp, backend, frontend, model, bug
Contributors
Donnie