Skip to content

Polymorphic Views cause compilation error due to out of order parsing #11260

Description

@bsi-nlawrence

Describe the bug
When using the extends keyword in views, if the subclassed view is parsed before the base view, it throws the following exception:

Error: Compile errors:\nErrors:\nCannot read properties of undefined (reading 'apply')

at ErrorReporter.throwIfAny (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/ErrorReporter.ts:214:11)
at DataSchemaCompiler.throwIfAnyErrors (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.ts:904:26)
at /cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.ts:551:16
at compile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/PrepareCompiler.ts:140:3)
at CompilerApi.compileSchema (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.ts:261:25)
at CompilerApi.applyRowLevelSecurity (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.ts:493:23)
at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:1395:58
at async Promise.all (index 0)
at ApiGateway.getNormalizedQueries (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:1383:48)
at ApiGateway.load (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:2042:9)

If I change the names of the files so that the base view is alphabetically before the subview, the code compiles fine. If the subview is named earlier alphabetically, I get the exception. I haven't read the code but it appears that the files are parsed alphabetically.

To Reproduce
See Cube Schema below.

  1. Place view A in view_a.js file
  2. Place view B in view_b.js file
  3. Execute Cube query to query either View A or B.
  4. Rename View A to view_c.js but do not change the view name to be view_c.
  5. Execute same cube query as before

Expected behavior
I would expect the base views to have been parsed previously before trying to parse completely the sub views.
Screenshots
If applicable, add screenshots to help explain your problem.

Minimally reproducible Cube Schema
In case your bug report is data modelling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.

Cube:

cube(`test`, {
    public: false,
    sql: `select 1 as id, 'test' as name`,

    dimensions: {
        id: {
            sql: `id`,
            type: `number`
        },
        name: {
            sql: `name`,
            type: `string`
        }
    }
});

View A (Located in file view_a.js):

view(`a_view`, {
    public: true,
    cubes: [
        {
            join_path: `test`,
            includes: [
                "id",
                "name"
            ]
        }
    ]
});

View B (Located in file view_b.js):

view(`b_view`, {
    public: true,
    extends: a_view,
    cubes: []
});

Version:
Tested on v 1.7.2 but applies as far back as 1.6.6 (this is the version I'm running in production so I didn't test previous to this version)

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugLEGACY. Use the Bug issue type instead

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions