Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

total: true crashes when the count query returns no row

Abierto Apto para principiantes
#11,973 0 comentarios 2 reacciones 0 asignados Ver en GitHub

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cube-js/cube

Todos los issues de cube-js/cube

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.