Budibase/budibase · critical · HTTPError

Failed to clear project assignments.

Error message

Failed to clear project assignments.

What it means

Thrown by clearAssignments when a bulkDocs batch removing the project from assigned documents reports per-document failures. The successfully updated docs are rolled back and a 500 HTTPError is raised, so project deletion is aborted with assignment state restored.

Source

Thrown at packages/server/src/sdk/workspace/projects/crud.ts:227

  }

  try {
    const results = await db.bulkDocs(changedDocs)
    const failures = results
      .map((result, index) => ({ result, index }))
      .filter(({ result }) => result.error)

    if (failures.length) {
      for (const { result, index } of results
        .map((result, index) => ({ result, index }))
        .filter(({ result }) => !result.error)) {
        const original = originals[index]
        rollbacks.push(async () => {
          await db.put({ ...original, _rev: result.rev })
        })
      }
      await rollbackAssignments(rollbacks)
      throw new HTTPError("Failed to clear project assignments.", 500)
    }

    for (const [index, result] of results.entries()) {
      const original = originals[index]
      rollbacks.push(async () => {
        await db.put({ ...original, _rev: result.rev })
      })
    }
  } catch (err) {
    if (!(err instanceof HTTPError)) {
      await rollbackAssignments(rollbacks)
    }
    throw err
  }

  return rollbacks
}

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Retry the project deletion once concurrent edits have settled — the rollback leaves state consistent
  2. Re-fetch the assigned docs and ensure no stale _rev conflicts exist before deleting
  3. Check server logs (the rollback failure detail is logged) to identify which docs failed and why
  4. Reduce concurrent automation/replication activity during deletion, then retry

Example fix

// before
deleteProject(id) // fails while users edit assigned docs
// after
try {
  await sdk.projects.remove(id, rev)
} catch (e) {
  if (String(e.message).includes("Failed to clear project assignments")) {
    await new Promise(r => setTimeout(r, 1000)) // let concurrent writes settle
    const fresh = await sdk.projects.get(id)
    if (fresh) await sdk.projects.remove(id, fresh._rev!)
  }
}
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try {
  await sdk.projects.remove(id, rev)
} catch (e) {
  if (String(e.message).includes("Failed to clear project assignments") && attempts < 3) {
    await new Promise(r => setTimeout(r, backoff))
    const fresh = await sdk.projects.get(id)
    if (fresh) await sdk.projects.remove(id, fresh._rev!)
  }
}

Prevention

When it happens

Trigger: Deleting a project (remove -> clearAssignments) while some assigned docs cannot be written — concurrent edits producing _rev conflicts during bulkDocs, validation rejections, or DB write errors on individual docs in the batch.

Common situations: Users editing rows/datasources at the same moment an admin deletes the project; replication or sync processes holding newer revisions; CouchDB contention under load.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/4ac34807051f58d0. Report an issue: GitHub.