Browse Source

fix: circular ref - validation correction

pull/7268/head
Pranav C 11 months ago
parent
commit
76adc81c35
  1. 8
      packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts
  2. 6
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  3. 1
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
  4. 7
      packages/nocodb/src/services/columns.service.ts

8
packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts

@ -10,7 +10,7 @@ describe('Formula parsing and type validation', () => {
formula: '1 + 2',
columns: [],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({})
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.NUMERIC);
@ -27,7 +27,7 @@ describe('Formula parsing and type validation', () => {
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({})
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.STRING);
@ -49,7 +49,7 @@ describe('Formula parsing and type validation', () => {
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({})
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.STRING);
@ -69,7 +69,7 @@ describe('Formula parsing and type validation', () => {
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({})
getMeta: async () => ({}),
});
expect(result1.dataType).toEqual(FormulaDataTypes.NUMERIC);

6
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -1400,6 +1400,7 @@ async function extractColumnIdentifierType({
export async function validateFormulaAndExtractTreeWithType({
formula,
column,
columns,
clientOrSqlUi,
getMeta,
@ -1420,6 +1421,7 @@ export async function validateFormulaAndExtractTreeWithType({
| typeof MssqlUi
| typeof SnowflakeUi
| typeof PgUi;
column?: ColumnType;
getMeta: (tableId: string) => Promise<any>;
}) {
const colAliasToColMap = {};
@ -1582,9 +1584,9 @@ export async function validateFormulaAndExtractTreeWithType({
res.name = col.id;
if (col?.uidt === UITypes.Formula) {
if (col?.uidt === UITypes.Formula && column) {
// check for circular reference
checkForCircularFormulaRef(col, parsedTree, columns);
checkForCircularFormulaRef(column, parsedTree, columns);
const formulaRes =
col.colOptions?.parsed_tree ||

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

@ -80,6 +80,7 @@ async function _formulaQueryBuilder(
tree = await validateFormulaAndExtractTreeWithType({
formula: _tree.replaceAll('{{', '{').replaceAll('}}', '}'),
columns,
column,
clientOrSqlUi: baseModelSqlv2.clientType as
| 'mysql'
| 'pg'

7
packages/nocodb/src/services/columns.service.ts

@ -213,6 +213,7 @@ export class ColumnsService {
colBody.parsed_tree = await validateFormulaAndExtractTreeWithType({
formula: colBody.formula_raw || colBody.formula,
columns: table.columns,
column,
clientOrSqlUi: source.type,
getMeta: async (modelId) => {
const model = await Model.get(modelId);
@ -947,6 +948,7 @@ export class ColumnsService {
parsed_tree: await validateFormulaAndExtractTreeWithType({
formula: new_formula_raw,
columns: table.columns,
column,
clientOrSqlUi: source.type,
getMeta: async (modelId) => {
const model = await Model.get(modelId);
@ -1018,6 +1020,7 @@ export class ColumnsService {
parsed_tree: await validateFormulaAndExtractTreeWithType({
formula: new_formula_raw,
columns: table.columns,
column,
clientOrSqlUi: source.type,
getMeta: async (modelId) => {
const model = await Model.get(modelId);
@ -1236,6 +1239,10 @@ export class ColumnsService {
formula:
colBody.formula_raw ||
colBody.formula?.replaceAll('{{', '{').replaceAll('}}', '}'),
column:{
...colBody,
colOptions: colBody,
},
columns: table.columns,
clientOrSqlUi: source.type,
getMeta: async (modelId) => {

Loading…
Cancel
Save