Changesets: staged deletes of gone records count as done, name stale ops
A web changeset with a staged record delete could not be applied after the record was deleted elsewhere (e.g. with the CLI), and the error only said "record N does not exist", so it was hard to find the operation to remove. A delete of a record that is already gone is now a no-op with a warning. Other operations that no longer apply fail with their number and summary (op_summary in the API), and the Changes page marks that row and offers to remove it from the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c37de31f4c
commit
49b1c872c9
7 files changed
+113
-17
No files matched your search
@@ -120,7 +120,7 @@ func applyOp(st *model.State, op model.Op, c *applyCtx) error {
|
||||
err = errf(KindBadRequest, "unknown operation %q", op.Kind)
|
||||
}
|
||||
if e, ok := AsError(err); ok && e.OpSeq == 0 {
|
||||
e.OpSeq = op.Seq
|
||||
e.OpSeq, e.OpSummary = op.Seq, op.Summary
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func applyRecordCreate(st *model.State, op model.Op, c *applyCtx) error {
|
||||
func applyRecordUpdate(st *model.State, op model.Op, c *applyCtx) error {
|
||||
r := st.Records[op.ID]
|
||||
if r == nil {
|
||||
return errf(KindNotFound, "record %d does not exist", op.ID)
|
||||
return errf(KindConflict, "the record (ID %d) no longer exists: it was deleted after this change was staged; remove this operation from the changeset", op.ID)
|
||||
}
|
||||
if err := checkVersion(op, r.Version, recordLabel(r)); err != nil {
|
||||
return err
|
||||
@@ -533,7 +533,10 @@ func applyRecordDelete(st *model.State, op model.Op, c *applyCtx) error {
|
||||
if op.ID != 0 {
|
||||
r := st.Records[op.ID]
|
||||
if r == nil {
|
||||
return errf(KindNotFound, "record %d does not exist", op.ID)
|
||||
// Deleted since this was staged (by someone else, or the
|
||||
// CLI): what the operation wanted is done.
|
||||
c.warn("%s: the record was already deleted outside this changeset, so there was nothing to delete", strings.TrimPrefix(op.Summary, "delete "))
|
||||
return nil
|
||||
}
|
||||
if err := checkVersion(op, r.Version, recordLabel(r)); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user