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

オープン 初心者向け
#20,110 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@lazerg がすでに取り組んでいます。

2026年12月1日 から。

  • #20120 @lazerg による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, typescript
領域
backend, database

調査の方向性

packages/drizzle/src/queries/parseParams.ts から始めて、getDateOnlyComparison 周辺のフィールドごとの演算子ループを調べてください。同じフィールドに対する時刻なしの日付境界が2つある場合の回帰テストを追加し、演算子の順序を逆にした場合も含めてください。issue の最小再現例では totalDocs が31になることを想定しています。両方の境界が適用され、既存の単一境界のクエリと完全なタイムスタンプを使うクエリが引き続き動作することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
TypeScript
スター
46.1k
フォーク
4.5k
平均マージ
2日 15時間
マージ済み PR(30日)
238

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

payloadcms/payload のほかの issue

payloadcms/payload の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。