hcengineering/platform · error
Sequence for ${training.class.Training} not found
Error message
Sequence for ${training.class.Training} not found What it means
getNextTrainingSeqNumber looks up the core Sequence document attached to training.class.Training and throws when none exists. Sequences allocate monotonic training numbers by incrementing a counter; without the Sequence document numbering cannot proceed. The Sequence must be created by the model setup/migration.
Source
Thrown at plugins/training-resources/src/utils/getNextTrainingSeqNumber.ts:14
//
// Copyright @ 2024 Hardcore Engineering Inc.
//
import { getClient } from '@hcengineering/presentation'
import core, { type Sequence } from '@hcengineering/core'
import training from '../plugin'
export async function getNextTrainingSeqNumber (): Promise<number> {
const client = getClient()
const sequence = await client.findOne(core.class.Sequence, { attachedTo: training.class.Training })
if (sequence === undefined) {
throw new Error(`Sequence for ${training.class.Training} not found`)
}
const inc = await client.update(sequence, { $inc: { sequence: 1 } }, true)
return (inc as { object: Sequence }).object.sequence
}
View on GitHub (pinned to 63e28dc964)
Solutions
- Create the missing Sequence document attached to training.class.Training (or re-run the model migration that seeds it).
- Verify with a query: findOne(core.class.Sequence, { attachedTo: training.class.Training }).
- Check that domain migration/seeding scripts ran on this workspace.
- Wrap training creation to surface a clear setup error when sequences are absent.
Example fix
// before
const seqNumber = await getNextTrainingSeqNumber()
// after
let seq = await client.findOne(core.class.Sequence, { attachedTo: training.class.Training })
if (seq === undefined) {
seq = await client.createDoc(core.class.Sequence, core.space.Model, { attachedTo: training.class.Training, sequence: 0 })
}
const seqNumber = seq.sequence + 1 Defensive patterns
Strategy: validation
Validate before calling
const seq = await client.findOne(core.class.Sequence, { attachedTo: training.class.Training })
if (seq === undefined) throw new Error('Training sequence not seeded; run model migration') Type guard
function sequenceExists(s: Sequence | undefined): s is Sequence { return s !== undefined } Try / catch
try { return await createTraining(data) } catch (e) { if (e.message.includes('Sequence')) await seedSequences(); else throw e } Prevention
- Ensure sequence-seeding migrations run on every workspace
- Never delete core Sequence documents
- Add a health check that all required sequences exist
When it happens
Trigger: Calling createTraining (which calls getNextTrainingSeqNumber) on a workspace where the training Sequence document was never seeded or was deleted.
Common situations: Fresh/test databases without full model seeding; migrations that reset sequences; someone deleting the Sequence object manually; upgrading a project where sequence creation step was added later.
Related errors
- Could not find a latest revision for training ${object.code}
- Training request #${ref} not found
- Training #${request.attachedTo} not found
- Current user is not allowed to create trainings
- Space #${parent.space} not found
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/372e825ce75f67f7.
Report an issue: GitHub.