Budibase/budibase · warning · HTTPError
Custom REST template cannot be deleted while it is in use
Error message
Custom REST template cannot be deleted while it is in use
What it means
This 409 Conflict HTTPError is returned when removeIfUnused determines the custom template is still referenced by one or more datasources. Deletion is blocked to avoid breaking datasources whose queries derive from the template.
Source
Thrown at packages/server/src/api/controllers/restTemplate.ts:154
export const destroy = async (
ctx: UserCtx<
void,
DeleteCustomRestTemplateResponse,
{ restTemplateId: string }
>
) => {
const { restTemplateId } = ctx.params
if (!isCustomRestTemplateId(restTemplateId)) {
throw new HTTPError("Invalid custom REST template ID", 400)
}
const removalResult = await sdk.restTemplates.removeIfUnused(restTemplateId)
if (removalResult === "missing") {
throw new HTTPError("Custom REST template not found", 404)
}
if (removalResult === "in_use") {
throw new HTTPError(
"Custom REST template cannot be deleted while it is in use",
409
)
}
ctx.body = {
message: `Custom REST template ${restTemplateId} deleted`,
}
}
View on GitHub (pinned to a81a902e9a)
Solutions
- Find and delete (or repoint) all datasources using this template, then retry the DELETE
- Use a different template for new datasources and migrate existing ones first
- Accept the 409 and surface a message asking the user to remove dependent datasources
Example fix
// before
DELETE /api/restTemplates/:id // 409 in_use
// after
await deleteDependentDatasources(templateId)
await api.delete(`/api/restTemplates/${templateId}`) // now succeeds Defensive patterns
Strategy: try-catch
Validate before calling
const datasources = await fetchDatasources()
const inUse = datasources.some(d => d.source === dsSource && usesTemplate(d, id))
if (inUse) throw new Error("Template is used by existing datasources") Type guard
null
Try / catch
try {
await deleteTemplate(id)
} catch (e) {
if (e?.status === 409) {
// prompt user to remove dependent datasources first
} else throw e
} Prevention
- List datasources referencing the template before deleting
- Repoint or delete dependent datasources first
- Communicate the 409 in-use rule to users in the delete confirmation dialog
When it happens
Trigger: DELETE on a custom REST template that is currently selected as the source of an existing REST datasource in the app.
Common situations: Teams sharing an app where someone tries to clean up a template another user wired into a datasource; deleting a template right after creating a datasource from it.
Related errors
- Project revision does not match.
- A row action with the same name already exists.
- Unable to bulk remove documents: ${res.error}
- Unable to remove top level directory - some skeleton files a
- Group name "${name}" is unavailable
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/6df18ddbcb5b64e8.
Report an issue: GitHub.