fix: table comparsion query for date type column#4649
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Updates API routes and service/tool call sites to pass Reviewed by Cursor Bugbot for commit daa1047. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes incorrect SQL casts for date column comparisons in the table filter query builder by threading column type metadata through
Confidence Score: 3/5The SQL builder change is logically correct, but the fix doesn't reach production because no call site passes the new Every real call site — both route handlers and all three service.ts call sites — omits the new apps/sim/lib/table/service.ts (lines 1438, 1821, 2132) and both route handler files need the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["buildFilterClause(filter, tableName, columns?)"] --> B["Build columnTypeMap from columns"]
B --> C{Field type?}
C -->|"$or / $and"| D["buildLogicalClause(..., columns)"]
D --> A
C -->|"regular field"| E["buildFieldCondition(..., columnTypeMap.get(field))"]
E --> F{Operator}
F -->|"$gt/$gte/$lt/$lte"| G["buildComparisonClause(..., columnType?)"]
G --> H{columnType === 'date'?}
H -->|Yes| I["(data->>'field')::timestamp OP value::timestamp"]
H -->|No| J["(data->>'field')::numeric OP value"]
Reviews (1): Last reviewed commit: "test: Update test for verify date column..." | Re-trigger Greptile |
| function getRawSqlString(sqlObj: SQL): string { | ||
| const obj = sqlObj as unknown as Record<string, unknown> | ||
| if (Array.isArray(obj['queryChunks'])) { | ||
| return (obj['queryChunks'] as unknown[]) | ||
| .map((chunk) => { | ||
| if (typeof chunk === 'string') return chunk | ||
| const raw = chunk as { value?: string[] } | ||
| return raw.value?.join('') ?? '' | ||
| }) | ||
| .join('') | ||
| } | ||
| return JSON.stringify(sqlObj) | ||
| } | ||
|
|
There was a problem hiding this comment.
getRawSqlString relies on undocumented drizzle internals
The helper reads queryChunks from the drizzle SQL object, which is not part of drizzle-orm's public API. The inner shape ({ value?: string[] }) also doesn't match the actual exported StringChunk / Param types in drizzle — a minor drizzle version bump could silently change the internal structure, causing these assertions to always pass (fallback to JSON.stringify) without actually testing the cast.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit baf6585. Configure here.

Summary
Fix broken date/timestamp comparisons in the table filter query builder.
buildComparisonClausealways cast comparison values with::numeric, so filters like{ createdAt: { $gte: '2024-01-01' } }on adate-typed column produced invalid SQL and returned no results. The fix threads column type metadata through the filter pipeline sodatecolumns use::timestampinstead.Fixes #(issue)
Type of Change
Testing
Unit tests in
apps/sim/lib/table/__tests__/sql.test.tsunder the newdate column typesuite:$gt,$gte,$lt,$ltewith adatecolumn — asserts::timestampis used and::numericis absent$gte+$lteon the same field)$and— asserts column type propagates through logical operatorsnumbercolumn still produces::numeric, not::timestampAlso verified that this fix works by manually build image.
Checklist
Screenshots/Videos
N/A — no UI changes.