cube icon indicating copy to clipboard operation
cube copied to clipboard

TypeConverting circular structure to JSON error when configuring two dataSources

Open smoorthyk opened this issue 2 years ago • 1 comments

Describe the bug I am configuring two dataSources - Mongo and Postgres - on my cubejs. When running any query on the Playground after configuration, the error message reads as below

TypeError: Converting circular structure to JSON --> starting at object with constructor 'Timeout' | property '_idlePrev' -> object with constructor 'TimersList' --- property '_idleNext' closes the circle at JSON.stringify () at OptsHandler.assertDriverFactoryResult (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:159:16) at /opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:225:21 at CubejsServerCore.contextToDbType (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:246:17) at CompilerApi.dbType (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/server.ts:453:28) at CompilerApi.getDbType (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:86:17) at CompilerApi.createQueryByDataSource (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:156:20) at RefreshScheduler.refreshCubesRefreshKey (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/RefreshScheduler.ts:249:32) at async Promise.all (index 0) at RefreshScheduler.runScheduledRefresh (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/server-core/src/core/RefreshScheduler.ts:199:9) at async Promise.all (index 0) at Timeout._onTimeout (/opt/cubejs/mongodb-dashboard/node_modules/@cubejs-backend/shared/src/promises.ts:139:9)

image

To Reproduce Steps to reproduce the behavior:

  1. Edit cube.js to include two dataSources
  2. Open Playground.
  3. Select any measure and dimension and run the query. For now, I havent created any joins between Postgres tables and Mongo collections. I have defined a schema that only looks at a mongo collection.
  4. See error

Expected behavior

  1. If I remove multiple dataSources and use just 'default' - pointing to Mongo, the queries run fine.
  2. The error happens only when two dataSources are specified in cube.js

Screenshots If applicable, add screenshots to help explain your problem.

Minimally reproducible Cube Schema cube.js

const PostgresDriver = require('@cubejs-backend/postgres-driver');
const MongoBIDriver = require('@cubejs-backend/mongobi-driver');

module.exports = {
    driverFactory: ({ dataSource }) => {
    if (dataSource === 'entity') {
      return new PostgresDriver({
        database: 'pgdbname',
        host: 'localhost',
        user: 'postgres',
        password: 'password',
        port: '5432',
      });
    }
    if (dataSource === 'default'){
        return new MongoBIDriver({
            database: 'test',
            host: 'localhost',
            user: 'some_mongo_user',
            password: 'password',
            port: '3307',
          });
    }

    throw new Error('dataSource is undefined');
  },
};
cube(`Partner`, {
  sql: `SELECT * FROM partner`,
  
  preAggregations: {
    // Pre-Aggregations definitions go here
    // Learn more here: https://cube.dev/docs/caching/pre-aggregations/getting-started  
  },
  
  joins: {
	  
    
  },
  
  measures: {
    count: {
      type: `count`,
      drillMembers: [id, partner_type]
    },
    
  },
  
  dimensions: {
    id: {
        sql: `id`,
        type: `number`,
        primaryKey: true,
    },
    partner_type: {
      sql: `partner_type`,
      type: `string`
    },
    
  },
  
  dataSource: `entity`
});

cube(`Load`, {
  sql: `SELECT * FROM test.load`,
    
  measures: {
    count: {
      type: `count`,
      drillMembers: [category]
    }, 
  },
  
  dimensions: {
    id: {
        sql: `_id`,
        type: `string`,
        primaryKey: true,
    },
    category: {
      sql: `category`,
      type: `string`
    },
    
  },
  
  dataSource: `default`
});

Version: 0.30.37

smoorthyk avatar Jul 28 '22 13:07 smoorthyk

@smoorthyk Please use new driverFactory format that returns DriverConfig object https://cube.dev/docs/config#driver-factory

paveltiunov avatar Jul 29 '22 05:07 paveltiunov