Browse Source

fix(nocodb): clear the cache to reflect the formula error in UI

pull/4776/head
Wing-Kam Wong 2 years ago
parent
commit
c244638630
  1. 13
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

13
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

@ -10,6 +10,8 @@ import LinkToAnotherRecordColumn from '../../../../../models/LinkToAnotherRecord
import LookupColumn from '../../../../../models/LookupColumn'; import LookupColumn from '../../../../../models/LookupColumn';
import { jsepCurlyHook, UITypes } from 'nocodb-sdk'; import { jsepCurlyHook, UITypes } from 'nocodb-sdk';
import { validateDateWithUnknownFormat } from '../helpers/formulaFnHelper'; import { validateDateWithUnknownFormat } from '../helpers/formulaFnHelper';
import { CacheGetType, CacheScope } from '../../../../../utils/globals';
import NocoCache from '../../../../../cache/NocoCache';
// todo: switch function based on database // todo: switch function based on database
@ -807,8 +809,6 @@ export default async function formulaQueryBuilderv2(
aliasToColumn aliasToColumn
); );
let formula;
try { try {
// dry run qb.builder to see if it will break the grid view or not // dry run qb.builder to see if it will break the grid view or not
// if so, set formula error and show empty selectQb instead // if so, set formula error and show empty selectQb instead
@ -827,10 +827,19 @@ export default async function formulaQueryBuilderv2(
} catch (e) { } catch (e) {
console.error(e); console.error(e);
if (column) { if (column) {
const formula = await column.getColOptions<FormulaColumn>();
// add formula error to show in UI // add formula error to show in UI
await FormulaColumn.update(formula.id, { await FormulaColumn.update(formula.id, {
error: e.message, error: e.message,
}); });
// update cache to reflect the error in UI
const key = `${CacheScope.COL_FORMULA}:${column.id}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o = { ...o, error: e.message };
// set cache
await NocoCache.set(key, o);
}
} }
throw new Error(`Formula error: ${e.message}`); throw new Error(`Formula error: ${e.message}`);
} }

Loading…
Cancel
Save