Skip to content

fix: subpage create conflict - #27

Open
AlexHardAtWork wants to merge 2 commits into
opendefensecloud:mainfrom
AlexHardAtWork:fix/subpage-create-conflict
Open

fix: subpage create conflict#27
AlexHardAtWork wants to merge 2 commits into
opendefensecloud:mainfrom
AlexHardAtWork:fix/subpage-create-conflict

Conversation

@AlexHardAtWork

Copy link
Copy Markdown

Fixes #24.

What

  • siblings() no longer filters archived_at IS NULL.
  • Both create paths map DocStoreError::Conflict to 409 doc.sort_key_conflict instead of
    falling through to a 500.

Why

Archived documents keep their sort_key and still count towards
UNIQUE (workspace_id, parent_id, sort_key), but siblings() hid them from key generation.
So after deleting a subpage, the next one regenerated the same key and the INSERT collided.
Letting generation see exactly what the constraint enforces removes the collision.

The 409 is worth having regardless: move_to already returns that code for the same
conflict, so the doc-mutating endpoints now agree, and a conflict stops being reported as an
internal error.

Why no migration

The alternative is a partial unique index over live rows only. That needs a migration and
a change to restore(), since a restored document's key may have been reused while it was
archived. The one-line query change achieves the same invariant with less surface.

Nothing user-visible changes: all three siblings() callers use it purely to compute a
sort key, never for display, and list_alive() still filters archived documents from the
tree.

Tests

New store test covering delete-then-create (crates/knot-storage/tests/documents.rs);
make test green. The 409 arm is deliberately untested — with generation fixed, only a race
between concurrent creates can still reach it, and there is no mock DocStore in the tree.

Not included

The lexorank exhaustion from the "bonus" section of #24 (the 8th subpage under one parent
regenerates "0m") is a separate defect and left for its own PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: creating a subpage returns 500 once a subpage has been deleted

1 participant