total: true crashes when the count query returns no row
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, mongodb
Línea de trabajo
The bug is in packages/cubejs-api-gateway/src/gateway.ts in getSqlResponseInternal. Look for the line that reads total.data[0][QueryAlias.TOTAL_COUNT]. The fix is to guard against total.data being empty. Check how other database drivers handle empty count results. Run the provided test query with a filter that matches no rows to reproduce the error.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
A load with "total": true throws when the companion count query returns no rows:
TypeError: Cannot read properties of undefined (reading 'total_count')
getSqlResponseInternal assumes that query always yields one row:
response.total = normalizedQuery.total
? Number(total.data[0][QueryAlias.TOTAL_COUNT])
: undefined;
To Reproduce
Use MongoBI (CUBEJS_DB_TYPE=mongobi).
Load a query that matches no rows and sets "total": true, for example:
{
"measures": ["Orders.count"],
"dimensions": ["Orders.status"],
"filters": [
{
"member": "Orders.status",
"operator": "equals",
"values": ["does-not-exist"]
}
],
"total": true
}
See Cannot read properties of undefined (reading 'total_count').
Expected behavior
An empty match returns data: [] and total: 0.
Screenshots
N/A
Minimally reproducible Cube Schema
Not data-modelling related. Any cube is enough; the failure is in the API gateway when MongoBI returns no row for the total query.
cube(`Orders`, {
sql_table: `orders`,
measures: {
count: {
type: `count`,
},
},
dimensions: {
status: {
sql: `status`,
type: `string`,
},
},
});
Version:
1.2.15. The same unguarded read is on current master in packages/cubejs-api-gateway/src/gateway.ts (getSqlResponseInternal).
Additional context
countAllQuery wraps the original SQL as SELECT COUNT(*) \total_count FROM (...). In SQL that returns one row, including 0 when the inner query is empty. MongoDB BI Connector maps COUNT(*) to an aggregation $group, and $group emits no document when its input is empty, so total.data is [] and total.data[0] is undefined.
- Lenguaje dominante
- Rust
- Estrellas
- 20.9k
- Forks
- 2.1k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 231
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cube-js/cube
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
cube-js/cube#11908 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cube-js/cube#11700 · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de cube-js/cube
Issues similares
-
bug CLI exec tool-calls
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
maintainer-needed p2 triaged ui windows
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
ai_p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/ClickHouse#123351 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
github/copilot-sdk#2804 · 1 comentario ·
Los mantenedores suelen responder en 1 día