cube-js / cube-js/cube

API error "One or more Primary key is required for '${cubeName}' cube" even when `allowUngroupedWithoutPrimaryKey` set to true

Open
#10,181 2 comments 0 reactions 1 assignee Claimed by @igorlukanin View on GitHub
data modeling question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Problem**

I already set `allowUngroupedWithoutPrimaryKey` in `cube.js`, but query with `ungrouped: true` still get error: `"One or more Primary key is required for '${cubeName}' cube"`

In `BaseQuery.js`, i found:
```javascript
/**
*
* @param {string} cubeName
* @returns {Array}
*/
primaryKeyNames(cubeName) {
const primaryKeys = this.cubeEvaluator.primaryKeys[cubeName];
if (!primaryKeys || !primaryKeys.length) {
throw new UserError_1.UserError(`One or more Primary key is required for '${cubeName}' cube`);
}
return primaryKeys.map((pk) => this.primaryKeyName(cubeName, pk));
}
```

`primaryKeyNames` always throws an error when a cube has no primary key. But shouldn’t it check `allowUngroupedWithoutPrimaryKey !== true` first?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.