Browse Source

fix: include formula tree generation part in validate

pull/7279/head
Pranav C 11 months ago
parent
commit
8a2df33690
  1. 2
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 33
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

2
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5909,7 +5909,7 @@ function getCompositePk(primaryKeys: Column[], row) {
return primaryKeys.map((c) => row[c.title]).join('___'); return primaryKeys.map((c) => row[c.title]).join('___');
} }
function haveFormulaColumn(columns: Column[]) { export function haveFormulaColumn(columns: Column[]) {
return columns.some((c) => c.uidt === UITypes.Formula); return columns.some((c) => c.uidt === UITypes.Formula);
} }

33
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -1057,23 +1057,24 @@ export default async function formulaQueryBuilderv2(
const knex = baseModelSqlv2.dbDriver; const knex = baseModelSqlv2.dbDriver;
// register jsep curly hook once only // register jsep curly hook once only
jsep.plugins.register(jsepCurlyHook); jsep.plugins.register(jsepCurlyHook);
// generate qb let qb;
const qb = await _formulaQueryBuilder( try {
baseModelSqlv2, // generate qb
_tree, qb = await _formulaQueryBuilder(
alias, baseModelSqlv2,
model, _tree,
aliasToColumn, alias,
tableAlias, model,
parsedTree ?? aliasToColumn,
(await column tableAlias,
?.getColOptions<FormulaColumn>() parsedTree ??
.then((formula) => formula?.getParsedTree())), (await column
); ?.getColOptions<FormulaColumn>()
.then((formula) => formula?.getParsedTree())),
);
if (!validateFormula) return qb; if (!validateFormula) return qb;
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
await baseModelSqlv2.execAndParse( await baseModelSqlv2.execAndParse(
@ -1095,6 +1096,8 @@ export default async function formulaQueryBuilderv2(
} }
} }
} catch (e) { } catch (e) {
if (!validateFormula) throw e;
console.error(e); console.error(e);
if (column) { if (column) {
const formula = await column.getColOptions<FormulaColumn>(); const formula = await column.getColOptions<FormulaColumn>();

Loading…
Cancel
Save