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

Đang mở Phù hợp với người mới
#2,381 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
data

Hướng nghiên cứu

Fallback về null nằm trong packages/db/src/query/expression-helpers.ts gần các dòng 390 và 472, còn guard ném 'Found complex expression' nằm ngay sau đó. Bắt đầu bằng cách tái hiện ba lời gọi trong issue với extractSimpleComparisons. Hoàn thành khi các lời gọi đó ném lỗi với các toán hạng bên phải không phải literal, trong khi eq(row.a, null) vẫn trả về value: null, và có một bài kiểm tra bao quát cả hai trường hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

  • 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.

Ngôn ngữ chính
TypeScript
Star
4k
Fork
286
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
104

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/db

Tất cả issue của TanStack/db

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.