{"record":{"id":"0c432c602d198efe","repo":"cube-js/cube","slug":"pre-aggregation-table-is-not-found-for-this-prea","errorCode":null,"errorMessage":"Pre-aggregation table is not found for ${this.preAggregation.tableName} after it was successfully created","messagePattern":"Pre-aggregation table is not found for (.+?) after it was successfully created","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts","lineNumber":277,"sourceCode":"    const versionEntry =\n      versionEntries.byStructure[`${this.preAggregation.tableName}_${structureVersion}`] ||\n      versionEntries.byTableName[this.preAggregation.tableName];\n\n    const newVersionEntry: VersionEntry = {\n      table_name: this.preAggregation.tableName,\n      structure_version: structureVersion,\n      content_version: contentVersion,\n      last_updated_at: nowTimestamp(client),\n      naming_version: 2,\n    };\n\n    const mostRecentResult: () => Promise<LoadPreAggregationResult> = async () => {\n      await this.loadCache.reset(this.preAggregation);\n      const lastVersion = getVersionEntryByContentVersion(\n        await this.loadCache.getVersionEntries(this.preAggregation)\n      );\n      if (!lastVersion) {\n        throw new Error(`Pre-aggregation table is not found for ${this.preAggregation.tableName} after it was successfully created`);\n      }\n      const targetTableName = this.targetTableName(lastVersion);\n      this.updateLastTouch(targetTableName);\n      return {\n        targetTableName,\n        refreshKeyValues: [],\n        lastUpdatedAt: lastVersion.last_updated_at,\n        buildRangeEnd: lastVersion.build_range_end,\n      };\n    };\n\n    if (this.forceBuild) {\n      this.logger('Force build pre-aggregation', {\n        preAggregation: this.preAggregation,\n        requestId: this.requestId,\n        metadata: this.metadata,\n        queryKey: this.preAggregationQueryKey(invalidationKeys),\n        newVersionEntry","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts#L259-L295","documentation":"After a pre-aggregation build was reported successful, mostRecentResult resets the load cache and re-fetches version entries expecting to find the last content version. If none is found, the newly created table cannot be located, so it throws. This is a consistency check: the build succeeded but the version/table lookup disagrees, typically due to cache/staleness or concurrent modifications.","triggerScenarios":"loadPreAggregationWithKeys completes a build, then getVersionEntries returns no versionEntryByContentVersion because the cache or table listing did not refresh; a concurrent process dropped/renamed the built table; reset did not clear a stale redis/queue entry.","commonSituations":"Race conditions between two refresh workers building the same pre-aggregation; cache staleness in redis when tables were built externally; partitioned pre-aggregations where expected partitions vanished between build and lookup.","solutions":["Clear the pre-aggregation cache (or restart the instance) to purge stale version entries, then re-run the query/build.","Check the external store/DB for the expected table name (targetTableName of lastVersion) — verify it actually exists and wasn't dropped concurrently.","Ensure only one refresh worker builds the same pre-aggregation at a time (queue locking / single scheduler).","Check redis/network connectivity for the orchestrator cache so reset() actually invalidates entries.","Update to a newer Cube version; several stale-cache races around builds have been fixed."],"exampleFix":"// before\nawait orchestratorApi.refreshScheduler()\n// after\nawait orchestratorApi.getPreAggregations().preAggregationCache.forceRebuild ? null : null\n// practical: clear cache then rebuild\nawait preAggregationsFacade.cleanup(); await preAggregationsFacade.build({ ... })","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await loader.loadPreAggregationWithKeys();\n} catch (e) {\n  if (String(e.message).includes('not found for') && String(e.message).includes('after it was successfully created')) {\n    await new Promise(r => setTimeout(r, 1000));\n    await loader.loadCache.reset(loader.preAggregation);\n    return loader.loadPreAggregationWithKeys(); // one retry after cache reset\n  }\n  throw e;\n}","preventionTips":["Use a single refresh worker per pre-aggregation to avoid build races.","Keep redis cache and external store consistent; monitor connectivity.","Avoid dropping pre-aggregation tables manually while queries run.","Upgrade Cube to pick up fixes for build/cache race conditions."],"tags":["pre-aggregation","build","cache-consistency","race-condition"],"backgroundTag":"preaggregation-not-found-after-build","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}