db-postgres: date-only range on a single field drops every operator after the first (greater_than_equal + less_than_equal)

Abierto Apto para principiantes
#20,110 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@lazerg ya está trabajando en esto.

Desde el 1/12/2026.

  • #20120 de @lazerg — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
88/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
postgresql, typescript
Área
backend, database

Línea de trabajo

Empieza en packages/drizzle/src/queries/parseParams.ts e inspecciona el bucle de operadores por campo alrededor de getDateOnlyComparison. Añade una prueba de regresión para dos límites de fecha sin hora en un mismo campo, incluido el orden inverso de los operadores; la reproducción mínima del issue espera que totalDocs sea 31. Confirma que se aplican ambos límites y que las consultas existentes con un solo límite y las consultas con marcas de tiempo completas siguen funcionando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the Bug

Since 3.94.0, a where with two comparison operators on the same date field, both given as date-only strings (YYYY-MM-DD), applies only the first operator. The second one is silently ignored. No error is raised; the query just returns too many documents.

await payload.find({
  collection: 'events',
  where: {
    date: {
      greater_than_equal: '2027-05-01',
      less_than_equal: '2027-05-31', // ignored
    },
  },
})
// → every event on or after 2027-05-01, not just May

Splitting the same range into and works correctly:

where: {
  and: [
    { date: { greater_than_equal: '2027-05-01' } },
    { date: { less_than_equal: '2027-05-31' } },
  ],
}
// → only May

Combined with a limit, this turns into wrong data rather than just extra rows. With limit: 31 and the default sort, the result is mostly documents from later months. That is how we hit it: a per-day pricing calendar started showing default values for days whose rows existed.

Cause: packages/drizzle/src/queries/parseParams.ts. The per-field loop

for (let operator of Object.keys(pathOperators)) {

handles each operator in turn. The new date-only branch (from getDateOnlyComparison) ends in break:

const dateOnlyComparison = getDateOnlyComparison({ config: adapter.payload.config, field, operator: originalOperator, value: val })
if (dateOnlyComparison) {
  const range = and(...dateOnlyComparison.constraints.map(/* … */))
  constraints.push(dateOnlyComparison.isNegated ? or(isNull(resolvedColumn), not(range)) : range)
  break // ← leaves the operator loop, so the remaining operators on this path are never processed
}

break exits for (operator of …), not just the current operator's handling. The comment just above the loop says "there can be multiple comparisons on a single path … loop on keys again here to handle each operator independently". The date-only branch breaks that contract. continue (or collecting the constraints and continuing) would keep the remaining operators.

Scope:

  • Only date fields where isDateOnlyFilter is true (pickerAppearance default / dayOnly), with values that match YYYY-MM-DD.
  • Full ISO timestamps (2027-05-01T00:00:00.000Z) don't take this branch and still work.
  • Seen in 3.94.1 and still present in 3.94.2 (the compiled dist/queries/parseParams.js is identical in that block).
  • Not checked: db-mongodb.
Link to the code that reproduces this issue

Minimal repro, any collection with a plain date field on @payloadcms/db-postgres ≥ 3.94.0:

// collection
{ slug: 'events', fields: [{ name: 'date', type: 'date', required: true }] }

// seed: one doc per day for 2027-05-01 … 2027-06-30 (61 docs)

const { totalDocs } = await payload.find({
  collection: 'events',
  where: { date: { greater_than_equal: '2027-05-01', less_than_equal: '2027-05-31' } },
  limit: 0,
})
expect(totalDocs).toBe(31) // actual: 61
Reproduction Steps
  1. Create a collection with a date field (no pickerAppearance, no timezone).
  2. Insert documents across two consecutive months.
  3. Query with date: { greater_than_equal: 'YYYY-MM-01', less_than_equal: 'YYYY-MM-31' } for the first month.
  4. Observe that documents from the second month are returned (the upper bound is ignored).
  5. Swap the operator order (less_than_equal first): now the lower bound is ignored.

Expected: both bounds apply, as in ≤ 3.93 and as with the equivalent and query.

Which area(s) are affected?

db-postgres (@payloadcms/drizzle), likely also db-sqlite / db-vercel-postgres since they share parseParams.

Environment Info
payload: 3.94.1 (also 3.94.2)
@payloadcms/db-postgres: 3.94.1
@payloadcms/drizzle: 3.94.1
Node: 24.23.0
Postgres: 17.9
Last working version: 3.93.0 (getDateOnlyComparison is absent from parseParams in 3.93.0, present from 3.94.0)
Lenguaje dominante
TypeScript
Estrellas
46.1k
Forks
4.5k
Merge medio
2 d 15 h
PR fusionados (30 d)
238

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 payloadcms/payload

Todos los issues de payloadcms/payload

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.