nocodb / nocodb

🔥 🔥 🔥 Open Source Airtable Alternative
https://nocodb.com
GNU Affero General Public License v3.0
43.86k stars 3.05k forks source link

🐛 Bug: TypeError: Cannot read properties of undefined (reading 'getChildColumn' #7615

Open TheRushingWookie opened 5 months ago

TheRushingWookie commented 5 months ago

Please confirm if bug report does NOT exists already ?

Steps to reproduce ?

I'll try to create a better repro

Desired Behavior

Project Details

Node: v18.5.0 Arch: arm64 Platform: linux Docker: false RootDB: sqlite3 PackageVersion: 0.204.0

Attachments

image
TheRushingWookie commented 5 months ago

I've added some debug logging and found its because of some RollupColumns have relation columns with undefined coloptions

The error is thrown after trying to handle this column object:

column Column {
  id: 'cl9ulg0geqce12f',
  source_id: 'b5oe4w5x6qnfqkg',
  base_id: 'pzl1z2u06qvb1th',
  fk_model_id: 'm3yi8lkipk4nrub',
  title: 'XXXXX',
  column_name: 'XXXX',
  uidt: 'Rollup',
  dt: 'varchar',
  np: null,
  ns: null,
  clen: null,
  cop: '2',
  pk: 0,
  pv: null,
  rqd: 0,
  un: null,
  ct: null,
  ai: 0,
  unique: null,
  cdf: null,
  cc: null,
  csn: null,
  dtx: 'string',
  dtxp: '',
  dtxs: '',
  au: 0,
  validate: null,
  virtual: null,
  deleted: null,
  system: 0,
  order: 3,
  created_at: '2024-02-13 02:54:43+00:00',
  updated_at: '2024-02-13 02:54:43+00:00',
  meta: null,
  description: null,
  colOptions: RollupColumn {
    id: 'rlewhk540wp2i33i',
    fk_column_id: 'cl9ulg0geqce12f',
    fk_relation_column_id: null,
    fk_rollup_column_id: null,
    rollup_function: null,
    deleted: null,
    created_at: '2024-02-13 02:54:43+00:00',
    updated_at: '2024-02-13 02:54:43+00:00'
  }
}

The relation column which is loaded here: https://github.com/nocodb/nocodb/blob/develop/packages/nocodb/src/db/genRollupSelectv2.ts#L23-L24 is undefined

The Relation Column which is used to load the relationColumnOption is

Column {
  id: 'ckzxxljmx2a6du4',
  source_id: 'bljgch1bqmbqfns',
  base_id: 'pldafbwmq3p7i0d',
  fk_model_id: 'mlhxglklqfvysz5',
  title: 'Id',
  column_name: 'id',
  uidt: 'ID',
  dt: 'integer',
  np: null,
  ns: '0',
  clen: null,
  cop: '0',
  pk: 1,
  pv: null,
  rqd: 1,
  un: 0,
  ct: 'int(11)',
  ai: 1,
  unique: null,
  cdf: null,
  cc: null,
  csn: null,
  dtx: 'specificType',
  dtxp: '',
  dtxs: '',
  au: 0,
  validate: null,
  virtual: null,
  deleted: null,
  system: 0,
  order: 1,
  created_at: '2024-02-13 02:17:35+00:00',
  updated_at: '2024-02-13 02:17:35+00:00',
  meta: null,
  description: null,
  colOptions: undefined
}

It looks like because fk_relation_column_id is null , we got the first column as the Relation column with pk=0;

TheRushingWookie commented 5 months ago

I think it might be related to https://github.com/nocodb/nocodb/commit/a6d746556ea324fd03acc2e173b73f8b3fdb2176#diff-12cd31b6ecb5583139cbce68cc55ec9d5eef9dcf55868b913523b45b829dbd35R1180-R1181

If ncRelationColumn is undefined, ncRollupColumnId will probably be wrong