Skip to content

Database issue with NWAC page? #1248

Closed
Closed

Description

@rustynwac

I am not understanding this.

Image

These are all directing to the same URL: https://avy-fx.org/admin/collections/pages/43

None of these pages are showing me what is currently published: https://nwac.avy-fx.org/education/workshops--programs

Zoe is having the following issues with this page so I went to look.

Image Image

She was trying to replace the images that were rendering next to the text here:

Image

Activity

  1. added
    needs-triage
    on Sep 1, 2026
  2. added this to the Summer 2026 milestone on Sep 1, 2026
  3. busbyk commented on Sep 1, 2026

    @busbyk
    Collaborator

    Fixed on page 43 (Workshops & Programs) — the list now shows a single row. Here's what was happening.

    The pages table was always fine: one document, id 43. But the admin list for a drafts-enabled collection doesn't read pages — it reads the versions table _pages_v filtered on latest = true, and maps each row to { id: parent, ...version }. Page 43 had several rows flagged latest, so it painted once per row, every one of them linking to /pages/43. That's also why the pagination counter disagreed with the number of rows on screen.

    The cause is upstream. createVersion in @payloadcms/drizzle inserts the new version row, then clears the previous latest flags in a separate, non-transactional statement guarded by a strict comparison:

    UPDATE _pages_v SET latest = false
    WHERE id != <new> AND parent = <parent> AND updated_at < <new updated_at>

    Any existing row whose updated_at equals the incoming one is skipped and keeps latest = true. Two version writes landing on the same millisecond both survive. Our three stale draft rows all carried the identical timestamp 16:45:35.574.

    Upstream issue: payloadcms/payload#17216 — Duplicate latest=1 version rows under autosave on D1/SQLite — createVersion clears prior latest flags non-transactionally with a strict updated_at< guard. Open, unlabelled, no linked PR. Reported against D1 with autosave on; we hit it on Turso with autosave off, so the guard is the bug, not the adapter.

    The fix, if this shows up again: open the affected doc and save a draft. The new version's updated_at is strictly greater than every stale row, so the demote clears all of them at once. No database surgery needed.

    Blast radius: I checked every page across all four tenants — 210 documents, and page 43 was the only one affected. Posts are clean. Rare, not systematic.

    One thing I have not confirmed: whether this explains what Zoe was hitting when replacing the images. The stale latest rows would make it ambiguous which version the editor and preview were resolving to, which is a plausible path to "my edits don't show up" — but that's a hypothesis, not something I verified. @rustynwac, can you and Zoe retry the image swap now that the duplicates are gone and let me know? If it still misbehaves, that's a separate bug and worth its own issue.

  4. busbyk commented on Sep 1, 2026

    @busbyk
    Collaborator

    Correcting my last comment — I told you and Zoe to retry the image swap, and that won't work on its own. Sorry. I've since dug into her screenshots and the images problem is a separate bug from the duplicate rows, with its own cause. Filed as #1249 — Media deletes are unguarded — dangling references block publish with an unexplained validation error.

    What's actually wrong: media 826 was deleted, but page 43 still references it in two blocks — the Northwest Snow and Avalanche Workshop block and the Going Deep block. That's why those two sections render as blank space, and it's what This field has the following invalid selections: 826, is complaining about.

    Two things made this so confusing:

    • It's referenced twice. Replace the image in one block, save, and you get the identical error again — because the other block is still pointing at the deleted file, and nothing on screen tells you it's there.
    • Draft saves work, Publish doesn't. Payload skips validation on draft saves, so a draft goes through fine and only Publish trips the error. From the editor's side that reads as "it saved but the site never changed."

    @rustynwac — what Zoe needs to do: replace the image in both the NSAW block and the Going Deep block, then Publish. Fixing only one won't clear it. If Publish still errors after both, the id in the message will have changed and there's a third reference somewhere — send me the new number and I'll trace it.

    The duplicate-rows problem is separate and already resolved; page 43 shows a single row now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions