Browse Source

fix(nocodb): handle existing formula select qb failure

pull/4776/head
Wing-Kam Wong 2 years ago
parent
commit
81fe17186c
  1. 30
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

30
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1206,14 +1206,34 @@ class BaseModelSqlv2 {
private async getSelectQueryBuilderForFormula(column: Column<any>) { private async getSelectQueryBuilderForFormula(column: Column<any>) {
const formula = await column.getColOptions<FormulaColumn>(); const formula = await column.getColOptions<FormulaColumn>();
if (formula.error) throw new Error(`Formula error: ${formula.error}`); if (formula.error) throw new Error(`Formula error: ${formula.error}`);
const selectQb = await formulaQueryBuilderv2( const qb = await formulaQueryBuilderv2(
formula.formula, formula.formula,
null, null,
this.dbDriver, this.dbDriver,
this.model this.model
); );
return selectQb; try {
// dry run the existing qb.builder to see if it will break the grid view or not
// if so, set formula error and show empty selectQb instead
await this.dbDriver(this.tnPath)
.select(qb.builder)
.as(sanitize(column.title));
// clean the previous formula error if the formula works this time
if (formula.error) {
await FormulaColumn.update(formula.id, {
error: null,
});
}
} catch (e) {
console.error(e);
// add formula error to show in UI
await FormulaColumn.update(formula.id, {
error: e.message,
});
throw new Error(`Formula error: ${e.message}`);
}
return qb;
} }
async getProto() { async getProto() {
@ -1502,7 +1522,6 @@ class BaseModelSqlv2 {
const selectQb = await this.getSelectQueryBuilderForFormula( const selectQb = await this.getSelectQueryBuilderForFormula(
column column
); );
// todo: verify syntax of as ? / ??
qb.select( qb.select(
this.dbDriver.raw(`?? as ??`, [ this.dbDriver.raw(`?? as ??`, [
selectQb.builder, selectQb.builder,
@ -1510,7 +1529,10 @@ class BaseModelSqlv2 {
]) ])
); );
} catch { } catch {
continue; // return dummy select
qb.select(
this.dbDriver.raw(`'ERR' as ??`, [sanitize(column.title)])
);
} }
} }
break; break;

Loading…
Cancel
Save