{"record":{"id":"282936b5de30c3cb","repo":"mastra-ai/mastra","slug":"dataset-not-found-args-datasetid","errorCode":null,"errorMessage":"Dataset not found: ${args.datasetId}","messagePattern":"Dataset not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/datasets/base.ts","lineNumber":175,"sourceCode":"   * Subclasses implement _doAddItem which handles SCD-2 versioning internally.\n   */\n  async addItem(args: AddDatasetItemInput): Promise<DatasetItem> {\n    const { datasetId, filters, ...item } = args;\n    const [result] = await this.batchInsertItems({ datasetId, filters, items: [item] });\n    return result!;\n  }\n\n  /** Subclasses implement actual storage add logic with SCD-2 versioning */\n  protected abstract _doAddItem(args: AddDatasetItemInput): Promise<DatasetItem>;\n\n  /**\n   * Update an item in a dataset. Validates changed fields against dataset schemas.\n   * Subclasses implement _doUpdateItem which handles SCD-2 versioning internally.\n   */\n  async updateItem(args: UpdateDatasetItemInput): Promise<DatasetItem> {\n    const dataset = await this.getDatasetById({ id: args.datasetId, filters: args.filters });\n    if (!dataset) {\n      throw new Error(`Dataset not found: ${args.datasetId}`);\n    }\n\n    const { id: _id, datasetId: _datasetId, filters: _filters, ...payload } = args;\n    validateDatasetItemPayloadSerialization(payload, 'item');\n\n    // Validate new values against schemas if enabled\n    const validator = getSchemaValidator();\n    const cacheKey = `dataset:${args.datasetId}`;\n\n    if (args.input !== undefined && dataset.inputSchema) {\n      validator.validate(args.input, dataset.inputSchema, 'input', `${cacheKey}:input`);\n    }\n\n    if (args.groundTruth !== undefined && dataset.groundTruthSchema) {\n      validator.validate(args.groundTruth, dataset.groundTruthSchema, 'groundTruth', `${cacheKey}:output`);\n    }\n\n    return this._doUpdateItem(args);","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/datasets/base.ts#L157-L193","documentation":"updateItem() fetches the parent dataset via getDatasetById before updating an item; if the dataset doesn't exist (or is hidden by args.filters) it throws \"Dataset not found: <datasetId>\". Items cannot exist without a valid parent dataset, so this is the missing-parent guard.","triggerScenarios":"Calling storage.updateItem({ datasetId }) where the dataset id is wrong, the dataset was deleted, or args.filters exclude it.","commonSituations":"Stale datasetId cached in application state after deletion, cross-environment ids (dev id used in prod), id built from concatenation producing a wrong value, filters mismatch.","solutions":["Confirm the dataset exists with getDatasetById using the same filters","Verify the datasetId source isn't stale (was the dataset deleted?)","Check storage backend/environment alignment","Create the dataset first if it genuinely doesn't exist"],"exampleFix":"// before\nawait storage.updateItem({ datasetId: oldId, id: itemId, values })\n// after\nconst ds = await storage.getDatasetById({ id: oldId });\nif (!ds) throw new Error(`Dataset ${oldId} missing; refresh dataset reference`);\nawait storage.updateItem({ datasetId: oldId, id: itemId, values });","handlingStrategy":"validation","validationCode":"const dataset = await storage.getDatasetById({ id: args.datasetId, filters: args.filters });\nif (!dataset) throw new Error(`dataset ${args.datasetId} not found`);","typeGuard":"null","tryCatchPattern":"try {\n  await storage.updateItem(args);\n} catch (e) {\n  if (e.message.startsWith('Dataset not found:')) { /* refresh dataset reference */ }\n  throw e;\n}","preventionTips":["Resolve datasetId from a live lookup, not cached state","Check filters match dataset scope","Watch for deletes invalidating stored datasetId references","Use the same storage instance/config that created the dataset"],"tags":["storage","datasets","not-found","items"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}