{"record":{"id":"9db8719dde863fe0","repo":"Budibase/budibase","slug":"legacy-view-metadata-is-missing","errorCode":null,"errorMessage":"Legacy view metadata is missing","messagePattern":"Legacy view metadata is missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/db/inMemoryView.ts","lineNumber":29,"sourceCode":"  view: DBView,\n  calculation: string,\n  group: boolean,\n  data: Row[]\n) {\n  // use a different ID each time for the DB, make sure they\n  // are always unique for each query, don't want overlap\n  // which could cause 409s\n  const db = new Pouch(utils.newid())\n  try {\n    // write all the docs to the in memory Pouch (remove revs)\n    await db.bulkDocs(\n      data.map(row => ({\n        ...row,\n        _rev: undefined,\n      }))\n    )\n    if (!view.meta) {\n      throw new Error(\"Legacy view metadata is missing\")\n    }\n\n    // Rebuild map/reduce from metadata to avoid executing untrusted map strings.\n    const groupByMulti =\n      view.meta.groupByMulti ?? view.meta.schema?.group?.type === \"array\"\n    const rebuiltView = viewBuilder(view.meta as any, groupByMulti)\n    let fn = (doc: Document, emit: any) => emit(doc._id)\n    // BUDI-7060 -> indirect eval call appears to cause issues in cloud\n    eval(\n      \"fn = \" +\n        rebuiltView?.map?.replace(\"function (doc)\", \"function (doc, emit)\")\n    )\n    const queryFns: any = {\n      meta: rebuiltView.meta,\n      map: fn,\n    }\n    if (rebuiltView.reduce) {\n      queryFns.reduce = rebuiltView.reduce","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/db/inMemoryView.ts#L11-L47","documentation":"`runView` executes a legacy (CouchDB-style) view whose metadata (`view.meta`) was rebuilt from stored data. Because map/reduce strings are not executed directly (untrusted code), the metadata object is required to reconstruct the view via viewBuilder. When the stored view has no meta, runView cannot rebuild it and throws 'Legacy view metadata is missing'.","triggerScenarios":"Calling fetchLegacyView for a view whose metadata document is absent or was not migrated (view.meta undefined) — e.g. querying a table's legacy view after an app import/upgrade where the meta doc was lost or never created.","commonSituations":"Upgrading old Budibase apps that predate the metadata-based view storage; views referenced in code that were created by another tool directly in CouchDB; partially failed migrations leaving view rows without their meta companion.","solutions":["Re-save the view in the builder so metadata is regenerated and stored.","Verify the view's metadata document exists in the app DB (view meta records) and restore it from a backup if missing.","Replace usage of the legacy view with a modern query or the in-memory view calculation path."],"exampleFix":"// before\nconst rows = await fetchLegacyView(table, \"groupName\") // meta missing\n// after: recreate the view via API so meta is persisted\nawait api.post(`/tables/${tableId}/views`, { name: \"groupName\", ...def })","handlingStrategy":"try-catch","validationCode":"// check the view has metadata before querying\nconst view = await db.get<View>(`view_${viewName}`) // or app meta lookup\nif (!view.meta) throw new Error(`Legacy view '${viewName}' has no metadata; recreate it before querying`)","typeGuard":null,"tryCatchPattern":"try {\n  return await runView({ table, viewName, params })\n} catch (err) {\n  if (err.message === \"Legacy view metadata is missing\") {\n    // recreate the view from its definition then retry once\n    await recreateLegacyView(table, viewName)\n    return await runView({ table, viewName, params })\n  }\n  throw err\n}","preventionTips":["Re-save legacy views after upgrading Budibase so metadata is generated.","Verify view meta documents exist when importing app exports.","Migrate legacy views to modern queries where possible."],"tags":["database","views","migration","legacy"],"backgroundTag":"legacy-view-metadata-missing","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}