-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Describe the bug
We have two cubes:
- User (base cube)
- Conversation (joined via
User.id = Conversation.user_id, 1:many)
Our business use case requires fetching all Users who have done 0 conversations within the last 30 days.
To do this, we need to apply a subquery filter on the Conversation's created date range when itβs joined to User.
This used to work correctly in Cube.js v0.33, but after upgrading to v1.3.36, the generated SQL no longer receives populated FILTER_PARAMS for the inDateRange filter, which breaks our subquery-based approach.
To Reproduce
Steps to reproduce the behavior:
- Start the playground server (make sure you're on v1.3.36)
- Copy and add this query
{
"measures": [
"Conversation.count_include_zero"
],
"dimensions": [
"User.id"
],
"timeDimensions": [],
"timezone": "Asia/Kolkata",
"limit": 5000,
"filters": [
{
"member": "User.organization_id",
"operator": "equals",
"values": ["1"]
},
{
"or": [
{
"member": "Conversation.created",
"operator": "inDateRange",
"values": [
"2025-06-15T00:00:00.000",
"2025-07-14T23:59:59.999"
]
},
{
"member": "Conversation.created",
"operator": "notSet"
}
]
}
]
}- Go to Generated SQL, you'll notice that the FILTER_PARAMS did not get populated in the subquery
Expected behavior
Cube.js should generate SQL similar to:
SELECT
"user".id,
count("conversation".id) as conversation_count
FROM tenant_user as "user"
LEFT JOIN (
SELECT * FROM tenant_conversation
WHERE 1=1 AND (
(created < ? AND created > ?)
OR created IS NULL
)
) as "conversation"
ON "user".id = "conversation".user_id
WHERE
"user".organization_id = 1
AND (
(
"conversation".created >= ? :: timestamp_tz
AND "conversation".created <= ? :: timestamp_tz
)
OR ("conversation".created IS NULL)
)
GROUP BY 1Screenshots
Bug screenshot in the latest version
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.
// cubes/User.js
cube(`User`, {
sql: `SELECT * FROM tenant_user`,
joins: {
Conversation: {
relationship: `one_to_many`,
sql: `${CUBE}.id = ${Conversation.user_id}`
}
},
measures: {
count: {
type: `count`,
drillMembers: [id]
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
},
organization_id: {
sql: `organization_id`,
type: `number`
}
}
});
// cubes/Conversation.js
cube(`Conversation`, {
sql: `SELECT * FROM tenant_conversation where ${FILTER_PARAMS.Conversation.created.filter("created")}`,
measures: {
count_include_zero: {
type: `count`,
sql: `id`,
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
},
user_id: {
sql: `user_id`,
type: `number`
},
created: {
sql: `created`,
type: `time`
}
}
});Version:
[1.3.36]
Additional context
β Actual behavior
Since upgrading to v1.3.36:
- The
FILTER_PARAMS.Conversation.created.inDateRangeis missing or empty. - This breaks our
count_include_zeromeasure that relies on it to apply the subquery date filter. - The generated SQL does not include the correct subquery or date filter.
π¦ Regression
| Version | Status |
|---|---|
| v0.33 | β Works |
| v1.3.36 | β Broken |
π Environment
| Item | Version |
|---|---|
| Cube.js | v1.3.36 |
| Database | Snowflake |
| Node.js | 22.14.0 |