hcengineering/platform · error
Training #${request.attachedTo} not found
Error message
Training #${request.attachedTo} not found What it means
After the request is found, the provider reads request.$lookup?.attachedTo — the parent Training resolved via lookup. If the lookup did not populate (undefined), the parent training cannot be resolved for the title. This usually means the training document was deleted or the lookup configuration did not fetch it.
Source
Thrown at plugins/training-resources/src/functions/trainingRequestObjectTitleProvider.ts:43
doc?: TrainingRequest
): Promise<string> {
const request = await client.findOne<TrainingRequest>(
training.class.TrainingRequest,
{
_id: ref
},
{
lookup: {
attachedTo: training.class.Training
}
}
)
if (request === undefined) {
throw new Error(`Training request #${ref} not found`)
}
const trainingObject = request.$lookup?.attachedTo
if (trainingObject === undefined) {
throw new Error(`Training #${request.attachedTo} not found`)
}
const revisionLabel = client.getHierarchy().getAttribute(trainingObject._class, 'revision').label
const revisionString = await translate(revisionLabel, {}, getCurrentLanguage())
return `${trainingObject.code} • ${trainingObject.title} • ${revisionString} ${trainingObject.revision}`
}
View on GitHub (pinned to 63e28dc964)
Solutions
- Verify the parent Training (request.attachedTo) exists in the database.
- Check the model's lookup configuration so $lookup.attachedTo is populated by the query.
- Clean up orphaned TrainingRequest documents whose parent trainings are gone.
- Add a fallback title when the parent is missing instead of relying on lookup.
Example fix
// before
const trainingObject = request.$lookup?.attachedTo
// after
const trainingObject = request.$lookup?.attachedTo ?? await client.findOne(training.class.Training, { _id: request.attachedTo }) Defensive patterns
Strategy: validation
Validate before calling
const parent = await client.findOne(training.class.Training, { _id: request.attachedTo })
if (parent === undefined) return 'orphaned request' Type guard
function hasAttachedParent<T extends { $lookup?: { attachedTo?: Doc } }>(r: T): boolean { return r.$lookup?.attachedTo !== undefined } Try / catch
try { return await titleProvider(client, ref) } catch { return await fallbackTitle(client, ref) } Prevention
- Ensure lookup declarations populate $lookup.attachedTo
- Cascade-delete or reassign requests when deleting trainings
- Audit for orphaned requests after deletions
When it happens
Trigger: TrainingRequest exists but its attachedTo Training no longer exists, or the findOne lookup options did not populate $lookup.attachedTo.
Common situations: Orphaned requests after a training hard-delete; hierarchy/lookup misconfiguration in the model; data restored partially from backup.
Related errors
- Training request #${ref} not found
- Could not find a latest revision for training ${object.code}
- Space #${parent.space} not found
- Space type #${space.type} not found
- Sequence for ${training.class.Training} not found
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/d7899426ab12d96e.
Report an issue: GitHub.