cube-js / cube-js/cube

Can't extend dynamically unless both models are defined in the same asyncModule

Open
#6,405 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 10h
Merged PRs (30d)
203

Description

**Describe the bug**
I have a model defined that I want to be able to extend dynamically, depending on the person querying it. When I try to do that (regardless of exactly how I do it) I am unable to do so. If I import the model from another file I get the following error: `Error: Can't match args for: 43`. If I try to reference it directly with just the name like I would in another file it throws a different error, saying it doesn't know what the model is. I'm not sure why this is, I did a little digging to the code but I couldn't find a specific issue that caused it.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a dynamic model in an asyncModule
2. Try to extend a model that is statically defined
3. It will error out when you try to query it

**Expected behavior**
I think I'd expect to be able to dynamically extend models.

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

**Minimally reproducible Cube Schema**
Define the following in two files:

```javascript
// cube_a.js
export default cube(`cube_a`, {
sql: `
SELECT 1 AS value UNION
SELECT 2 AS value
`,

measures: {
count: {
type: `count`
}
}
});

// dynamiccube.js
asyncModule(async () => {
cube(`cube_b`, {
extends: require('./cube_a.js'),

measures: {
sum: {
sql: `value`,
type: `sum`
}
}
});
});
```

**Version:**
v0.32.21

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the two schema entry points shown in cube_a.js and dynamiccube.js, including the asyncModule callback and extends reference. Trace how the dynamic model and statically defined model are resolved during querying; done means cube_b can extend cube_a across files without either reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.