extractSimpleComparisons returns value: null when the right side of a comparison isn't a literal

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

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

まだ誰も着手していません。

評価

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

調査の方向性

null へのフォールバックは packages/db/src/query/expression-helpers.ts の390行目と472行目付近にあり、'Found complex expression' をスローするガードはその直後にあります。まず、issue にある3つの呼び出しを extractSimpleComparisons に対して再現してください。これらの呼び出しが右辺がリテラルでない場合にエラーをスローし、一方で eq(row.a, null) は引き続き value: null を返し、両方のケースを対象とするテストがある状態を完了とします。

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

説明

  • I've validated the bug against the latest version of DB packages

Describe the bug

extractSimpleComparisons is documented to throw on expressions it can't represent as a simple comparison, but a comparison whose right side is a column or a function doesn't throw. It returns value: null, so a queryFn built on it sends a filter against null to the backend with no error.

When the right side isn't a literal it falls back to null (expression-helpers.ts:390 and :472), and the guard after it only rejects undefined, so the "Found complex expression" error can't fire for this case.

To Reproduce

import { IR, extractSimpleComparisons } from "@tanstack/db"

const a = new IR.PropRef(["a"])
const b = new IR.PropRef(["b"])

console.log(extractSimpleComparisons(new IR.Func("eq", [a, b])))
console.log(extractSimpleComparisons(new IR.Func("eq", [a, new IR.Func("lower", [b])])))
console.log(extractSimpleComparisons(new IR.Func("not", [new IR.Func("gt", [a, b])])))

This prints:

[ { field: [ 'a' ], operator: 'eq', value: null } ]
[ { field: [ 'a' ], operator: 'eq', value: null } ]
[ { field: [ 'a' ], operator: 'not_gt', value: null } ]

The same happens through a live query. On an on-demand collection, .where(({ row }) => eq(row.a, lower(row.b))) passes loadSubset a where that extractSimpleComparisons reads as { field: ['a'], operator: 'eq', value: null }.

Expected behavior

These calls throw extractSimpleComparisons requires simple field-value comparisons. Found complex expression for 'eq' operator. (or 'not(gt)'), as they would for any other expression it can't represent. A literal null, such as eq(row.a, null), should keep returning value: null.

Additional context

@tanstack/db 1.0.0-rc.1.4, Node 24.12.0. The lines above are unchanged on main at 6ec538ecd.

Falling back to undefined instead of null at those two lines would let the existing guard throw. I can open a PR if that looks right to you.

主要言語
TypeScript
スター
4k
フォーク
286
平均マージ
1日 1時間
マージ済み PR(30日)
104

環境構築

はじめの一歩

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

TanStack/db のほかの issue

TanStack/db の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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